View Javadoc

1   package org.catacomb.numeric.data;
2   
3   import java.lang.reflect.Field;
4   
5   import org.catacomb.report.E;
6   
7   
8   public class DSlice extends StackSingleSlice implements NumVector {
9   
10  
11      double[] data;
12  
13      int npcache;
14  
15  
16      public DSlice(BlockStack bs, String fnm, Field f, String u, String t) {
17          super(bs, fnm, f, u, t);
18          npcache = 0;
19          data = new double[10];
20      }
21  
22  
23  
24  
25      public double[] getData() {
26          if (upToDate()) {
27              // nothing to do;
28  
29          } else {
30              int np = blockStack.getSize();
31              if (np > data.length) {
32                  double[] dn = new double[np + np/2 + 10];
33                  for (int i = 0; i < npcache; i++) {
34                      dn[i] = data[i];
35                  }
36                  data = dn;
37              }
38  
39              try {
40  
41                  for (int i = npcache; i < np; i++) {
42                      data[i] = field.getDouble(blockStack.getBlock(i));
43                  }
44                  npcache = np;
45  
46              } catch (Exception ex) {
47                  E.error("exception reading slice from block stack " + this + " " + ex);
48              }
49  
50          }
51          cacheTime.now();
52  
53          return data;
54      }
55  
56  
57      void clearCache() {
58          npcache = 0;
59      }
60  
61  
62  
63  
64  
65  }