-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensorData.java
109 lines (90 loc) · 2.47 KB
/
SensorData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.io.DataInputStream;
import java.io.IOException;
import java.lang.String;
import edu.wisc.ssec.mcidas.AncillaryData;
/**
* SensorData creates a object used to gather image data on a line
* by line basis. Only access method at present is nextLine.
*
* @version 1.3 6 Aug 1999
* @author Tommy Jasmin, SSEC
*/
class SensorData {
private DataInputStream dis;
private AncillaryData ad;
private int dw = 0;
private int nb = 0;
private int ps = 0;
private boolean isSwapped;
/**
*
* constructor
*
* @param DIS data input stream
* @param AD AncillaryData object
*
*/
public SensorData(DataInputStream DIS, AncillaryData AD)
{
// store references passed in
dis = DIS;
ad = AD;
// allocate the line buffer we'll use
// dataLine = new float[ad.getNumElements()][ad.getNumBands()];
// store data width, needed so nextLine knows how many bytes to read
dw = ad.getDataWidth();
// store number of bands, needed for value counts to read in
nb = ad.getNumBands();
// store line prefix size
ps = ad.getPrefixSize();
isSwapped = ad.isSwapped();
}
/**
*
* load next line of data into float array provided
*
* @param dataLine buffer to return data in
*
*/
public float[] nextLine(float [] dataLine)
throws IOException
{
byte tmpByte;
int tmpInt;
// first, eat any line prefix bytes
for (int i = 0; i < ps; i++) {
tmpByte = dis.readByte();
}
switch (dw) {
case 1:
for (int i = 0; i < ad.getNumElements() * ad.getNumBands(); i++) {
dataLine[i] = (float) dis.readByte();
}
break;
case 4:
for (int i = 0; i < ad.getNumElements() * ad.getNumBands(); i++) {
tmpInt = dis.readInt();
if (isSwapped) {
dataLine[i] = (float) ((( (tmpInt >> 16) & 0xff) << 8 ) |
( (tmpInt >> 24) & 0xff));
} else {
dataLine[i] = (float)tmpInt;
}
}
break;
case 2:
default:
for (int i = 0; i < ad.getNumElements() * ad.getNumBands(); i++) {
tmpInt = ((int) dis.readShort() & 0xFFFF);
if (isSwapped) {
dataLine[i] = (float) (( (tmpInt & 0xff) << 8 ) |
( (tmpInt >> 8) & 0xff)) ;
} else {
dataLine[i] = (float) tmpInt;
}
}
break;
}
return dataLine;
}
}