1 | package PIANOS.datastructures; |
2 | |
3 | import PIANOS.exceptions.*; |
4 | import PIANOS.datastructures.*; |
5 | |
6 | import java.util.*; |
7 | |
8 | /* |
9 | Note: The thing calling generaterFreqCode and generateGenCode |
10 | must add _dp to real constants. For example, "1.0_dp", not "1.0". |
11 | */ |
12 | |
13 | public class BetaDistribution extends Distribution |
14 | { |
15 | |
16 | public BetaDistribution() |
17 | { |
18 | super(2); |
19 | parameterType[0] = 1; // real |
20 | parameterType[1] = 1; // real |
21 | } |
22 | |
23 | public ArrayList<String> getIntroduction() |
24 | { |
25 | ArrayList<String> result = new ArrayList<String>(); |
26 | result.add("EXTERNAL G01EEF"); |
27 | result.add("EXTERNAL G05FEF"); |
28 | return result; |
29 | } |
30 | |
31 | public ArrayList<String> getFreqCode(String[] parameters) throws IllegalParametersException |
32 | { |
33 | // Parameters are: a, b, point, result |
34 | |
35 | if (parameters.length != 4) |
36 | { |
37 | throw new IllegalParametersException("Trying to use beta distribution with illegal parameters."); |
38 | } |
39 | |
40 | /* |
41 | The code we want to generate looks like this: |
42 | ifail = -1 |
43 | CALL G01EEF(point, a, b, 1.0_dp, temp_real, temp_real, result, ifail) |
44 | IF (ifail /= 0) THEN |
45 | WRITE (*, *) 'Error when trying to calculate frequency of the beta distribution, parameters: a = ', a, 'b = ', b |
46 | STOP |
47 | END IF |
48 | */ |
49 | |
50 | ArrayList<String> result = new ArrayList<String>(); |
51 | |
52 | result.add("ifail = -1"); |
53 | result.add("CALL G01EEF(" + parameters[2] +", " + parameters[0] + ", " + parameters[1] + |
54 | ", 1.0_dp, temp_real, temp_real, " + parameters[3] + ", ifail)"); |
55 | result.add("IF (ifail /= 0) THEN"); |
56 | result.add("WRITE (*, *) 'Error when trying to calculate frequency of the beta distribution, parameters: a = ', " + |
57 | parameters[0] + ", 'b = ', " + parameters[1]); |
58 | result.add("STOP"); |
59 | result.add("END IF"); |
60 | |
61 | return result; |
62 | } |
63 | |
64 | public ArrayList<String> getGenCode(String[] parameters) throws IllegalParametersException |
65 | { |
66 | // Parameters are: a, b, result |
67 | if (parameters.length != 3) |
68 | { |
69 | throw new IllegalParametersException("Trying to use beta distribution with illegal parameters."); |
70 | } |
71 | |
72 | /* |
73 | The code we want to generate looks like this: |
74 | ifail = 0 |
75 | CALL G05FEF(a, b, SIZE(result), result, ifail) |
76 | IF (ifail /= 0) THEN |
77 | WRITE (*, *) 'Error when trying to generate random numbers from beta distribution, parameters: a = ', a, 'b = ', b |
78 | STOP |
79 | END IF |
80 | */ |
81 | |
82 | ArrayList<String> result = new ArrayList<String>(); |
83 | |
84 | result.add("ifail = 0"); |
85 | result.add("CALL G05FEF(" + parameters[0] + ", " + parameters[1] + ", SIZE(" + parameters[2] + |
86 | "), " + parameters[2] + ", ifail)"); |
87 | result.add("IF (ifail /= 0) THEN"); |
88 | result.add("WRITE (*, *) 'Error when trying to generate random numbers from beta distribution, " + |
89 | "parameters: a = ', " + parameters[0] + ", 'b = ', " + parameters[1]); |
90 | result.add("STOP"); |
91 | result.add("END IF"); |
92 | |
93 | return result; |
94 | |
95 | /* |
96 | Note: |
97 | The code generated by this method uses the following already introduced variables: |
98 | INTEGER :: ifail |
99 | */ |
100 | } |
101 | } |