1 | package PIANOS.generator; |
2 | |
3 | import PIANOS.datastructures.ComputationalModel; |
4 | import PIANOS.io.*; |
5 | import java.io.*; |
6 | import java.util.*; |
7 | |
8 | /** |
9 | * This class is used to generate the Fortran module "definitions". |
10 | */ |
11 | |
12 | public class Definitions { |
13 | |
14 | /** Generates and writes the Fortran module definitions.f90. |
15 | * @param model The model this simulation is related to |
16 | */ |
17 | public static void generateDefinitions(ComputationalModel model) throws IOException { |
18 | FortranWriter out = new FortranWriter("definitions.f90"); |
19 | |
20 | ArrayList <String> toWrite = new ArrayList<String>(); |
21 | |
22 | toWrite.add("MODULE definitions"); |
23 | toWrite.add(""); |
24 | toWrite.add("TYPE variable_int"); |
25 | toWrite.add(""); |
26 | toWrite.add("LOGICAL :: is_data"); |
27 | toWrite.add(""); |
28 | toWrite.add("LOGICAL :: initial_value_set"); |
29 | toWrite.add(""); |
30 | toWrite.add("INTEGER :: value"); |
31 | toWrite.add("INTEGER :: new_value"); |
32 | toWrite.add(""); |
33 | toWrite.add("INTEGER :: successful_changes"); |
34 | toWrite.add(""); |
35 | if (model.getUpdateStrategy().equals("random")){ |
36 | toWrite.add("! HARD-CODED: these two are here iff the update strategy is random"); |
37 | toWrite.add("INTEGER :: updates_wanted"); |
38 | toWrite.add("INTEGER :: update_count"); |
39 | } |
40 | toWrite.add(""); |
41 | toWrite.add("END TYPE variable_int"); |
42 | toWrite.add(""); |
43 | toWrite.add("TYPE variable_real"); |
44 | toWrite.add(""); |
45 | toWrite.add("LOGICAL :: is_data"); |
46 | toWrite.add(""); |
47 | toWrite.add("LOGICAL :: initial_value_set"); |
48 | toWrite.add(""); |
49 | toWrite.add("REAL (KIND=SELECTED_REAL_KIND(8, 0)) :: value"); |
50 | toWrite.add("REAL (KIND=SELECTED_REAL_KIND(8, 0)) :: new_value"); |
51 | toWrite.add(""); |
52 | toWrite.add("INTEGER :: successful_changes"); |
53 | toWrite.add(""); |
54 | if (model.getUpdateStrategy().equals("random")){ |
55 | toWrite.add("! HARD-CODED: these two are here iff the update strategy is random"); |
56 | toWrite.add("INTEGER :: updates_wanted"); |
57 | toWrite.add("INTEGER :: update_count"); |
58 | } |
59 | toWrite.add(""); |
60 | toWrite.add(""); |
61 | toWrite.add("END TYPE variable_real"); |
62 | toWrite.add(""); |
63 | toWrite.add(""); |
64 | toWrite.add("TYPE variables_int"); |
65 | toWrite.add(""); |
66 | toWrite.add("INTEGER :: buffer_index"); |
67 | toWrite.add("INTEGER, ALLOCATABLE, DIMENSION(:) :: buffer"); |
68 | toWrite.add(""); |
69 | toWrite.add("! the places of the variables missing in data."); |
70 | toWrite.add("INTEGER, ALLOCATABLE, DIMENSION(:) :: one_dim_missing"); |
71 | toWrite.add("INTEGER, ALLOCATABLE, DIMENSION(:, :) :: two_dim_missing"); |
72 | toWrite.add("! n, 2"); |
73 | toWrite.add(""); |
74 | toWrite.add("TYPE(variable_int), ALLOCATABLE, DIMENSION(:) :: one_dim"); |
75 | toWrite.add("TYPE(variable_int), ALLOCATABLE, DIMENSION(:, :) :: two_dim"); |
76 | toWrite.add(""); |
77 | toWrite.add("END TYPE variables_int"); |
78 | toWrite.add(""); |
79 | toWrite.add("TYPE variables_real"); |
80 | toWrite.add(""); |
81 | toWrite.add("INTEGER :: buffer_index"); |
82 | toWrite.add("REAL (KIND=SELECTED_REAL_KIND(8, 0)), ALLOCATABLE, DIMENSION(:) :: buffer"); |
83 | toWrite.add(""); |
84 | toWrite.add("! the places of the variables missing in data."); |
85 | toWrite.add("INTEGER, ALLOCATABLE, DIMENSION(:) :: one_dim_missing"); |
86 | toWrite.add("INTEGER, ALLOCATABLE, DIMENSION(:, :) :: two_dim_missing"); |
87 | toWrite.add(""); |
88 | toWrite.add(""); |
89 | toWrite.add("TYPE(variable_real), ALLOCATABLE, DIMENSION(:) :: one_dim"); |
90 | toWrite.add("TYPE(variable_real), ALLOCATABLE, DIMENSION(:, :) :: two_dim"); |
91 | toWrite.add(""); |
92 | toWrite.add("END TYPE variables_real"); |
93 | toWrite.add(""); |
94 | toWrite.add("END MODULE definitions"); |
95 | |
96 | out.write(toWrite.toArray(new String[toWrite.size()])); |
97 | } |
98 | } |