<commit_before>MODULE IMSL_REPLACEMENTS
  

  !*****************************************************************************
  ! This module provides the required functionality that is provided by the  
  ! IMSL library in the original work.
  !*****************************************************************************

  CONTAINS

!*******************************************************************************
!*******************************************************************************
SUBROUTINE LFCDS(a, matrix, b , factor, c, d)
! I WANT THE INTERFACE CLOSER TO THE ORGINAL IMSL IF POSSIBLE
!This subroutine generates the cholesky factor of the argument 'matrix' and stores
!the result in the argument 'factor'.
!
IMPLICIT NONE
!Defining arguments
REAL, INTENT(IN)	    :: matrix(:,:)
REAL, INTENT(INOUT)	:: factor(:,:), d
INTEGER,  INTENT(IN):: a, b, c 
!Definition of local variables

INTEGER				:: i, n, k, j
REAL					:: sums
REAL, ALLOCATABLE	:: clon(:,:)
!Algorithm
factor = 0
n = size(matrix,1)
ALLOCATE(clon(n,n))
clon = matrix
DO j = 1, n
   sums = 0.0
   DO k = 1, j-1
      sums = sums + clon(j,k)**2
   END DO
 
clon(j,j) = sqrt(clon(j,j) - sums)
    
   DO i = j + 1, n
      sums = 0.0
      DO k = 1, j-1
         sums = sums + clon(j,k)*clon(i,k)
      END DO
      clon(i,j) = (clon(i,j) - sums)/clon(j,j)
   END DO
END DO
!Transfer information from matrix to factor
DO i = 1,n
  DO j = 1,n
     IF(i <= j) factor(j,i) = clon(j,i) 
  END DO
END DO
END SUBROUTINE 

!********************************************************************
SUBROUTINE normal1(vec, mean, variance)
!
!This subroutine generates a univariate sample of random numbers form N(mean, variance)
!using the Box-Muller algorithm.
!
IMPLICIT NONE
!Defining arguments
REAL, INTENT(OUT)	:: vec(:,:)
REAL, INTENT(IN)		:: mean(:), variance(:,:)
!Defining local variables
REAL, PARAMETER		:: pi = 3.1415926
REAL, ALLOCATABLE    :: u(:), r(:)
INTEGER   			:: g, i, s
!Algorithm
s = size(vec,1) 
ALLOCATE(u(2*s))
ALLOCATE(r(2*s))
CALL random_number(u)
DO g = 1, 2*s, 2
   r(g) 	= sqrt(-2*log(u(g)))*cos(2*pi*u(g+1)) 
   r(g+1)	= sqrt(-2*log(u(g)))*sin(2*pi*u(g+1)) 
END DO
DO i = 1,s 
   vec(i,1) = mean(1) + sqrt(variance(1,1))*r(i)			
END DO
END SUBROUTINE normal1

!********************************************************************
SUBROUTINE RNNOR(dim, draw)
!
! This subroutine draws a single deviate from a  mutlivariate normal distribution with mean zero.
!
IMPLICIT NONE
!Defining arguments
INTEGER, INTENT(IN)				:: dim
REAL, INTENT(OUT)				:: draw(4)
!Defining local variables
INTEGER				:: g, n, i
REAL			:: zero(1) = 0.0, one(1,1) = 1.0, z(4,1)
!Algorithm
CALL normal1(z, zero, one)

draw = z(:,1)

END SUBROUTINE 


!********************************************************************
SUBROUTINE RNSET(a)
!
! St random seed
!
IMPLICIT NONE
!Defining arguments
INTEGER, INTENT(IN)				:: a


END SUBROUTINE 


END MODULE

!*******************************************************************************
!*******************************************************************************
PROGRAM dp3asim

  !*****************************************************************************  
  ! There are only minor modifications to the original source code.
  ! The input and output connections are opened and the commenting
  ! style is changed to comply with the FORTRAN95 standard. Line
  ! breaks are removed.
  !*****************************************************************************

	!Interface to IMSL replacements
	USE IMSL_REPLACEMENTS
  
!********************************************************
!*  PROGRAM TO CONSTRUCT MONTE CARLO DATA FOR DP MODEL  *
!********************************************************
!*  TUITION COST INCLUDED                               *
!********************************************************
!*  VERSION WITH LAGGED SCHOOL AS STATE VARIABLE        *
!********************************************************
      INTEGER KSTATE(40,14000,4)
      INTEGER FSTATE(40,40,40,11,2)
      INTEGER KMAX(40)
      DIMENSION EMAX(40,14000),EMAX1(40,14000)
      DIMENSION BETA(2,6),A(4,4),RHO(4,4)
      DIMENSION SIGMA(4)
      DIMENSION EU1(5000,40),EU2(5000,40),C(5000,40),B(5000,40)
      DIMENSION RNN(4)
      DIMENSION PROB(40,4)
      DIMENSION PROB1(40,4)
      INTEGER X1,X2,E,T


! Open files
open(9,file='in1a.txt')
  
open(10,file='otest.txt')
  
open(11,file='ftest.txt')


      READ(9,1500) NPER,NPOP,DRAW,DRAW1,TAU
      WRITE(10,1500) NPER,NPOP,DRAW,DRAW1,TAU
 1500 FORMAT(1x,i3,1x,i5,1x,f7.0,1x,f6.0,1x,f6.2)
!C     GAMA= 0.577
      WNA=-9.99
      do 1 J=1,2
      READ(9,1501) (BETA(J,k),k=1,6)<commit_msg>cleanup cholesky<commit_after>MODULE IMSL_REPLACEMENTS
  

  !*****************************************************************************
  ! This module provides the required functionality that is provided by the  
  ! IMSL library in the original work.
  !*****************************************************************************

  IMPLICIT NONE

  PUBLIC

  CONTAINS

!*******************************************************************************
!*******************************************************************************
SUBROUTINE LFCDS(a, matrix, b, factor, c, d)
! I WANT THE INTERFACE CLOSER TO THE ORGINAL IMSL IF POSSIBLE
!This subroutine generates the cholesky factor of the argument 'matrix' and stores
!the result in the argument 'factor'.
!
IMPLICIT NONE
!Defining arguments
REAL, INTENT(IN)	    :: matrix(:,:)
REAL, INTENT(INOUT)	:: factor(:,:), d
INTEGER,  INTENT(IN):: a, b, c 
!Definition of local variables

INTEGER				:: i, n, k, j
REAL					:: sums
REAL, ALLOCATABLE	:: clon(:,:)
!Algorithm
factor = 0
n = size(matrix,1)
ALLOCATE(clon(n,n))
clon = matrix
DO j = 1, n
   sums = 0.0
   DO k = 1, j-1
      sums = sums + clon(j,k)**2
   END DO
 
clon(j,j) = sqrt(clon(j,j) - sums)
    
   DO i = j + 1, n
      sums = 0.0
      DO k = 1, j-1
         sums = sums + clon(j,k)*clon(i,k)
      END DO
      clon(i,j) = (clon(i,j) - sums)/clon(j,j)
   END DO
END DO
!Transfer information from matrix to factor
DO i = 1,n
  DO j = 1,n
     IF(i <= j) factor(j,i) = clon(j,i) 
  END DO
END DO
END SUBROUTINE 

  !***************************************************************************** 
  !***************************************************************************** 
  SUBROUTINE RNNOR(dim, draw)

    !
    ! This subroutine generates deviates from a standard normal distribution using 
    ! the Box-Muller algorithm.
    !

    !/* external objects    */

    INTEGER, INTENT(IN)	:: dim

    REAL, INTENT(OUT)   :: draw(dim)
    
    !/* internal objects    */

    INTEGER             :: g 

    REAL, PARAMETER     :: pi = 3.141592653589793238462643383279502884197
    REAL, ALLOCATABLE   :: u(:), r(:)

    !--------------------------------------------------------------------------- 
    ! Algorithm
    !--------------------------------------------------------------------------- 

    ! Allocate containers
    ALLOCATE(u(2*dim)); ALLOCATE(r(2*dim))

    ! Call uniform deviates
    CALL random_number(u)

    ! Apply Box-Muller transform
    DO g = 1, 2*dim, 2

       r(g)   = SQRT(-2*LOG(u(g)))*COS(2*pi*u(g+1)) 
       r(g+1) = SQRT(-2*LOG(u(g)))*SIN(2*pi*u(g+1)) 

    END DO

    ! Extract relevant floats
    DO g = 1, dim 

       draw(g) = r(g)     

    END DO

  END SUBROUTINE 

!*******************************************************************************
!*******************************************************************************
SUBROUTINE RNSET(a)
!
! St random seed
!
IMPLICIT NONE
!Defining arguments
INTEGER, INTENT(IN)				:: a


END SUBROUTINE 

!*******************************************************************************
!*******************************************************************************

END MODULE

!*******************************************************************************
!*******************************************************************************
PROGRAM dp3asim

  !*****************************************************************************  
  ! There are only minor modifications to the original source code.
  ! The input and output connections are opened and the commenting
  ! style is changed to comply with the FORTRAN95 standard. Line
  ! breaks are removed.
  !***************************************************************************** 

  ! Interface to IMSL replacements
  USE IMSL_REPLACEMENTS
  
!********************************************************
!*  PROGRAM TO CONSTRUCT MONTE CARLO DATA FOR DP MODEL  *
!********************************************************
!*  TUITION COST INCLUDED                               *
!********************************************************
!*  VERSION WITH LAGGED SCHOOL AS STATE VARIABLE        *
!********************************************************
      INTEGER KSTATE(40,14000,4)
      INTEGER FSTATE(40,40,40,11,2)
      INTEGER KMAX(40)
      DIMENSION EMAX(40,14000),EMAX1(40,14000)
      DIMENSION BETA(2,6),A(4,4),RHO(4,4)
      DIMENSION SIGMA(4)
      DIMENSION EU1(5000,40),EU2(5000,40),C(5000,40),B(5000,40)
      DIMENSION RNN(4)
      DIMENSION PROB(40,4)
      DIMENSION PROB1(40,4)
      INTEGER X1,X2,E,T


  ! Open files
  open(9,file='in1.txt')
    
  open(10,file='otest.txt')
    
  open(11,file='ftest.txt')


      READ(9,1500) NPER,NPOP,DRAW,DRAW1,TAU
      WRITE(10,1500) NPER,NPOP,DRAW,DRAW1,TAU
 1500 FORMAT(1x,i3,1x,i5,1x,f7.0,1x,f6.0,1x,f6.2)
!C     GAMA= 0.577
      WNA=-9.99
      do 1 J=1,2
      READ(9,1501) (BETA(J,k),k=1,6)
{'fraction_non_alphanumeric': 0.36087408949011446, 'fraction_numerical': 0.0404786680541103, 'mean_word_length': 3.883638211382114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654249', 'n_tokens_mistral': 3483, 'n_tokens_neox': 3044, 'n_words': 750}