View Javadoc

1   package org.catacomb.numeric.difnet.model;
2   
3   import java.util.ArrayList;
4   
5   import org.catacomb.numeric.difnet.NetState;
6   import org.catacomb.report.E;
7   
8   
9   
10  
11  
12  public class BasicNetRecorder {
13  
14      ArrayList<PointRecorder> pointRecorders;
15  
16      int nrec;
17      String[] recLabels;
18      int[] recIndices;
19  
20  
21      public BasicNetRecorder() {
22          pointRecorders = new ArrayList<PointRecorder>();
23      }
24  
25      public void addPotentialRecorder(String id, String tag, String probePort) {
26          pointRecorders.add(new PointRecorder(id, tag, probePort));
27      }
28  
29  
30      public void resolve(int[] remeshMap) {
31          nrec = pointRecorders.size();
32          recLabels = new String[nrec];
33          recIndices = new int[nrec];
34  
35          int iel = 0;
36          for (PointRecorder pr : pointRecorders) {
37              recLabels[iel] = pr.getID();
38  
39              String sp = pr.getPort();
40              if (sp == null || sp.length() == 0) {
41                  E.warning("null port on probe " + pr);
42              } else {
43                  try {
44                      int ipt = Integer.parseInt(sp);
45                      if (ipt < 0) {
46                          E.warning("negative port id in " + pr);
47  
48                      } else {
49                          recIndices[iel] = remeshMap[ipt];
50  
51                          //E.info("new index for rec " + iel + " original pt " + ipt +
52                          //      " is " + recIndices[iel]);
53                      }
54  
55  
56                  } catch (Exception ex) {
57                      E.error("must have integer port ids, not " + sp);
58                  }
59              }
60  
61              iel += 1;
62          }
63      }
64  
65  
66  
67      public String[] getRecorderLabels() {
68          return recLabels;
69      }
70  
71      public double[] getValues(NetState netState) {
72          double[] ret = new double[nrec];
73          for (int i = 0; i < nrec; i++) {
74              ret[i] = netState.getValueAt(recIndices[i]);
75          }
76          return ret;
77      }
78  
79  }
80  
81  
82  
83  
84  class PointRecorder {
85  
86      String id;
87      String tag;
88      String port;
89  
90      PointRecorder(String sid, String stag, String pp) {
91          id = sid;
92          tag = stag;
93          port = pp;
94      }
95  
96      public String getID() {
97          return id;
98      }
99  
100     public String getTag() {
101         return tag;
102     }
103 
104     public String getPort() {
105         return port;
106     }
107 
108 }