View Javadoc

1   package edu.iris.dmc.seedcodec;
2   
3   /***
4    * DecompressedData.java
5    *
6    *
7    * Created: Thu Nov 21 13:03:44 2002
8    *
9    * @author <a href="mailto:crotwell@seis.sc.edu">Philip Crotwell</a>
10   * @version
11   */
12  
13  public class DecompressedData implements B1000Types {
14  
15      public DecompressedData(int[] data) {
16          this.iData = data;
17      }
18      public DecompressedData(short[] data) {
19          this.sData = data;
20      }
21      public DecompressedData(float[] data) {
22          this.fData = data;
23      }
24      public DecompressedData(double[] data) {
25          this.dData = data;
26      }
27  
28  
29      /*** returns an integer that represent the java primitive that the data
30       *  decompresses to. This is to allow for SEED types 4 and 5, float and
31       *  double, which cannot be represented as int without a loss of precision.
32       *  @see B1000Types.java for the values.
33       *  @see http://www.fdsn.org for the seed manual, blockette 1000, that defines these values.
34       */
35      public int getType() {
36          if (iData != null) {
37              return INTEGER;
38          } else  if (sData != null) {
39              return SHORT;
40          } else  if (fData != null) {
41              return FLOAT;
42          } else {
43              // assume double
44              return DOUBLE;
45          } // end of else
46      }
47  
48      /*** returns a string version of the type for printing in error messages. */
49      public String getTypeString() {
50          if (iData != null) {
51              return "INTEGER";
52          } else  if (sData != null) {
53              return "SHORT";
54          } else  if (fData != null) {
55              return "FLOAT";
56          } else {
57              // assume double
58              return "DOUBLE";
59          } // end of else
60      }
61  
62      /*** Converts the data to an int array if possible without loss. Otherwise
63       *  returns null.
64       */
65      public int[] getAsInt() {
66          int[] temp;
67          if (iData != null) {
68              return iData;
69          } else if (sData != null) {
70              temp = new int[sData.length];
71              for (int i=0; i<sData.length; i++) {
72                  temp[i] = sData[i];
73              }
74              return temp;
75          }
76          return null;
77      }
78  
79      /*** Converts the data to a short array if possible without loss. Otherwise
80       *  returns null.
81       */
82      public short[] getAsShort() {
83          if (sData != null) {
84              return sData;
85          }
86          return null;
87      }
88  
89      /*** Converts the data to a float array if possible without loss. Otherwise
90       *  returns null.
91       */
92      public float[] getAsFloat() {
93          float[] temp;
94          if (fData != null) {
95              return fData;
96          } else if (iData != null) {
97              temp = new float[iData.length];
98              for (int i=0; i<iData.length; i++) {
99                  temp[i] = iData[i];
100             }
101             return temp;
102         } else if (sData != null) {
103             temp = new float[sData.length];
104             for (int i=0; i<sData.length; i++) {
105                 temp[i] = sData[i];
106             }
107             return temp;
108         }
109         return null;
110     }
111 
112     /*** Converts the data to a double array if possible without loss. Otherwise
113      *  returns null.
114      */
115     public double[] getAsDouble() {
116         double[] temp;
117         if (dData != null) {
118             return dData;
119         } else if (fData != null) {
120             dData = new double[fData.length];
121             for (int i=0; i<fData.length; i++) {
122                 dData[i] = fData[i];
123             }
124             return dData;
125         } else if (iData != null) {
126             dData = new double[iData.length];
127             for (int i=0; i<iData.length; i++) {
128                 dData[i] = iData[i];
129             }
130             return dData;
131         } else if (sData != null) {
132             dData = new double[sData.length];
133             for (int i=0; i<sData.length; i++) {
134                 dData[i] = sData[i];
135             }
136             return dData;
137         }
138         return null;
139     }
140 
141     /*** holds a temp int array of the data elements.
142      */
143     protected int[] iData = null;
144 
145     /*** holds a temp short array of the data elements.
146      */
147     protected short[] sData = null;
148 
149     /*** holds a temp float array of the data elements.
150      */
151     protected float[] fData = null;
152 
153     /*** holds a temp double array of the data elements.
154      */
155     protected double[] dData = null;
156 
157 }// DecompressedData