-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBFbalance.java
More file actions
189 lines (155 loc) · 7.31 KB
/
Copy pathBFbalance.java
File metadata and controls
189 lines (155 loc) · 7.31 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// BFbalance.java
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import java.util.*;
import java.io.*;
import java.security.*;
public class BFbalance{
protected Vector<String> oRawData, oAdjustedData;
protected int fromLineNo, toLineNo;
protected double randomDist=0.5f;
protected SecureRandom r;
// constructor
public BFbalance(){
try{
// initialize variables
oRawData = new Vector<String>();
oAdjustedData = new Vector<String>();
r = new SecureRandom();
// load parameters from config file
Properties prop = new Properties();
prop.load(new BufferedReader(new FileReader("balanceConfig.txt")));
String FileName = prop.getProperty("FileName");
fromLineNo = Integer.parseInt(prop.getProperty("fromLineNo"));
toLineNo = Integer.parseInt(prop.getProperty("toLineNo"));
randomDist = StrictMath.abs(Double.parseDouble(prop.getProperty("randomDist")));
if(StrictMath.abs(randomDist)>0.5f)
randomDist = 0.5f;
// fetch raw data - gsi-8 format of digital level
BufferedReader in = new BufferedReader(new FileReader(FileName));
String sLine = null;
while((sLine=in.readLine())!=null){
oRawData.add(sLine);
oAdjustedData.add(sLine);
}
// check parameters
if(fromLineNo<1)
throw new RuntimeException("value of 'fromLineNo' in config file is TOO small!");
if(toLineNo>oRawData.size())
throw new RuntimeException("value of 'toLineNo' in config file is TOO large!");
if(fromLineNo >= toLineNo)
throw new RuntimeException("value of 'fromLineNo' in config file must smaller than that of 'toLineNo'!");
}catch(Exception e){
System.out.println(e);
System.exit(0);
}
}
public void compute(){
int index = fromLineNo-1;
while(index != -1){
double deltaDist = r.nextDouble() * randomDist - randomDist/2.0f;
index=scan4BS(oAdjustedData, index);
if(index!=-1){
int backsightIndex = index;
String sBacksightData = oAdjustedData.get(backsightIndex);
StringTokenizer st = new StringTokenizer(sBacksightData);
String backsightPointid = st.nextToken();
double backsightDist = gsi8_util.getHD(st.nextToken());
String backsightReading = st.nextToken();
// System.out.print((index + 1) + ", ");
index=scan4FS(oAdjustedData, index);
if(index!=-1){
String sForsightData = oAdjustedData.get(index);
st = new StringTokenizer(sForsightData);
String forsightPointid = st.nextToken();
double foresightDist = gsi8_util.getHD(st.nextToken());
String foresightReading = st.nextToken();
// adjusting fore / back sight distances
double adjustedDist = (backsightDist + foresightDist)/2.0f;
backsightDist = adjustedDist + deltaDist;
foresightDist = adjustedDist - deltaDist;
sBacksightData = backsightPointid + " " + gsi8_util.getHDWord('8', backsightDist) + " " + backsightReading + " ";
oAdjustedData.set(backsightIndex, sBacksightData);
sForsightData = forsightPointid + " " + gsi8_util.getHDWord('8', foresightDist) + " " + foresightReading + " ";
oAdjustedData.set(index, sForsightData);
// adjusting distance balance in foresight result
String foresightResult = oAdjustedData.get(index+1);
st = new StringTokenizer(foresightResult);
String resultBlockID = st.nextToken();
st.nextToken(); // just consume it
String totalDist = st.nextToken();
String groundHight = st.nextToken();
foresightResult = resultBlockID + " " + gsi8_util.getDistBalWord('8', deltaDist*2.0f) + " " + totalDist + " " + groundHight;
oAdjustedData.set(index+1, foresightResult);
// testing output
// System.out.println(sBacksightData);
// System.out.println(sForsightData);
// System.out.println(foresightResult);
// System.out.println(index+1);
}
}
}
}
// scan for next BS
protected int scan4BS(Vector<String> v, int iFrom){
int result = -1;
if(iFrom<0)
return -1;
int index = iFrom;
while(result==-1 && index<toLineNo){
StringTokenizer st = new StringTokenizer(oAdjustedData.get(index));
if(st.hasMoreTokens()){
if((st.nextToken()).startsWith("11")){ // first word
if((st.nextToken()).startsWith("32")){ // second word
String thirdWord = st.nextToken(); // whether it is BS
if(thirdWord.startsWith("331")){
result = index;
}
}
}
}
index++;
}
return result;
}
// scan for next FS
protected int scan4FS(Vector<String> v, int iFrom){
int result = -1;
if(iFrom<0)
return -1;
int index = iFrom;
while(result==-1 && index<toLineNo){
StringTokenizer st = new StringTokenizer(oAdjustedData.get(index));
if(st.hasMoreTokens()){
if((st.nextToken()).startsWith("11")){ // first word
if((st.nextToken()).startsWith("32")){ // second word
String thirdWord = st.nextToken(); // whether it is FS
if(thirdWord.startsWith("332")){
result = index;
}
}
}
}
index++;
}
return result;
}
public void printResult(){
for(int index=0; index<oAdjustedData.size(); index++){
System.out.println(oAdjustedData.get(index));
}
}
public static void main(String[] args) throws Exception{
BFbalance b = new BFbalance();
b.compute();
b.printResult();
}
}