00001 REAL FUNCTION genchi(df) 00002 C********************************************************************** 00003 C 00004 C REAL FUNCTION GENCHI( DF ) 00005 C Generate random value of CHIsquare variable 00006 C 00007 C 00008 C Function 00009 C 00010 C 00011 C Generates random deviate from the distribution of a chisquare 00012 C with DF degrees of freedom random variable. 00013 C 00014 C 00015 C Arguments 00016 C 00017 C 00018 C DF --> Degrees of freedom of the chisquare 00019 C (Must be positive) 00020 C REAL DF 00021 C 00022 C 00023 C Method 00024 C 00025 C 00026 C Uses relation between chisquare and gamma. 00027 C 00028 C********************************************************************** 00029 C .. Scalar Arguments .. 00030 REAL df 00031 C .. 00032 C .. External Functions .. 00033 C REAL gengam 00034 C EXTERNAL gengam 00035 REAL sgamma 00036 EXTERNAL sgamma 00037 C .. 00038 C .. Executable Statements .. 00039 IF (.NOT. (df.LE.0.0)) GO TO 10 00040 WRITE (*,*) 'DF <= 0 in GENCHI - ABORT' 00041 WRITE (*,*) 'Value of DF: ',df 00042 CALL XSTOPX ('DF <= 0 in GENCHI - ABORT') 00043 00044 C JJV changed this to call sgamma directly 00045 C 10 genchi = 2.0*gengam(1.0,df/2.0) 00046 10 genchi = 2.0*sgamma(df/2.0) 00047 RETURN 00048 00049 END