| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.data.reader; |
| 20 |
|
| 21 |
import java.text.ParseException; |
| 22 |
import java.util.ArrayList; |
| 23 |
import java.util.Date; |
| 24 |
import java.util.Iterator; |
| 25 |
import java.util.List; |
| 26 |
|
| 27 |
import footleg.cavesurvey.converter.CaveConverter; |
| 28 |
import footleg.cavesurvey.converter.Logger; |
| 29 |
import footleg.cavesurvey.converter.CaveConverter.BearingUnit; |
| 30 |
import footleg.cavesurvey.converter.CaveConverter.GradientUnit; |
| 31 |
import footleg.cavesurvey.converter.CaveConverter.LengthUnit; |
| 32 |
import footleg.cavesurvey.data.model.CaveSurvey; |
| 33 |
import footleg.cavesurvey.data.model.Equate; |
| 34 |
import footleg.cavesurvey.data.model.SurveyLeg; |
| 35 |
import footleg.cavesurvey.data.model.SurveySeries; |
| 36 |
import footleg.cavesurvey.tools.UtilityFunctions; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public class SurvexParser { |
| 53 |
private Logger logger; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public SurvexParser( Logger logger ) { |
| 60 |
super(); |
| 61 |
this.logger = logger; |
| 62 |
} |
| 63 |
|
| 64 |
private class DataBlockProperties { |
| 65 |
|
| 66 |
public DataBlockProperties(boolean duplicateFlag, boolean splayFlag, boolean surfaceFlag, boolean noSurvey) { |
| 67 |
super(); |
| 68 |
this.duplicateFlag = duplicateFlag; |
| 69 |
this.splayFlag = splayFlag; |
| 70 |
this.surfaceFlag = surfaceFlag; |
| 71 |
this.noSurvey = noSurvey; |
| 72 |
} |
| 73 |
|
| 74 |
public DataBlockProperties(DataBlockProperties parentBlock) { |
| 75 |
super(); |
| 76 |
this.duplicateFlag = parentBlock.duplicateFlag; |
| 77 |
this.splayFlag = parentBlock.splayFlag; |
| 78 |
this.surfaceFlag = parentBlock.surfaceFlag; |
| 79 |
this.noSurvey = parentBlock.noSurvey; |
| 80 |
this.parentBlock = parentBlock; |
| 81 |
} |
| 82 |
|
| 83 |
private boolean duplicateFlag = false; |
| 84 |
private boolean splayFlag = false; |
| 85 |
private boolean surfaceFlag = false; |
| 86 |
private boolean noSurvey = false; |
| 87 |
private DataBlockProperties parentBlock; |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public CaveSurvey parseFile( List<String> surveyFileData, List<String> multifileRefs ) throws ParseException { |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
int state = 0; |
| 109 |
|
| 110 |
|
| 111 |
CaveSurvey allSeries = new CaveSurvey(logger); |
| 112 |
|
| 113 |
|
| 114 |
List<SurveySeries> seriesStack = new ArrayList<SurveySeries>(); |
| 115 |
|
| 116 |
|
| 117 |
List<String> nameStack = new ArrayList<String>(); |
| 118 |
|
| 119 |
|
| 120 |
List<Equate> equates = new ArrayList<Equate>(); |
| 121 |
|
| 122 |
|
| 123 |
SurveySeries liveSeries = null; |
| 124 |
|
| 125 |
|
| 126 |
List<String> dataOrder = new ArrayList<String>(); |
| 127 |
|
| 128 |
|
| 129 |
DataBlockProperties blockProps = new DataBlockProperties( false, false, false, false ); |
| 130 |
|
| 131 |
|
| 132 |
for ( int fileDataIdx=0; fileDataIdx < surveyFileData.size(); fileDataIdx++ ) { |
| 133 |
|
| 134 |
int lineNo = fileDataIdx + 1; |
| 135 |
String dataLine = surveyFileData.get(fileDataIdx); |
| 136 |
String lineRef = "" + lineNo; |
| 137 |
if ( multifileRefs != null ) { |
| 138 |
lineRef = multifileRefs.get( fileDataIdx ); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
int commentPos = dataLine.indexOf(';'); |
| 144 |
if ( commentPos > -1 ) { |
| 145 |
dataLine = dataLine.substring(0, commentPos); |
| 146 |
} |
| 147 |
|
| 148 |
dataLine = dataLine.trim(); |
| 149 |
|
| 150 |
if ( dataLine.length() > 0 ) { |
| 151 |
|
| 152 |
if ( dataLine.charAt(0) == '*' ) { |
| 153 |
|
| 154 |
String[] data = UtilityFunctions.cleanAndSplitDataLine( dataLine.substring(1) ); |
| 155 |
|
| 156 |
String cmd = data[0]; |
| 157 |
|
| 158 |
|
| 159 |
if ( cmd.compareToIgnoreCase("BEGIN") == 0 ) { |
| 160 |
|
| 161 |
state = 1; |
| 162 |
if (data.length == 2) { |
| 163 |
|
| 164 |
liveSeries = new SurveySeries(data[1]); |
| 165 |
|
| 166 |
nameStack.add(data[1]); |
| 167 |
|
| 168 |
double tapeCal = 0.0; |
| 169 |
double compassCal = 0.0; |
| 170 |
double clinoCal = 0.0; |
| 171 |
double declinationCal = 0.0; |
| 172 |
|
| 173 |
if (seriesStack.size() > 0) { |
| 174 |
SurveySeries series = seriesStack.get( seriesStack.size() - 1 ); |
| 175 |
tapeCal = series.getTapeCalibration(LengthUnit.Metres); |
| 176 |
compassCal = series.getCompassCalibration(BearingUnit.Degrees); |
| 177 |
clinoCal = series.getClinoCalibration(GradientUnit.Degrees); |
| 178 |
declinationCal = series.getDeclination(); |
| 179 |
dataOrder = series.getDataOrder(); |
| 180 |
} |
| 181 |
|
| 182 |
seriesStack.add(liveSeries); |
| 183 |
|
| 184 |
|
| 185 |
liveSeries.setTapeCalibration(tapeCal, LengthUnit.Metres); |
| 186 |
liveSeries.setCompassCalibration(compassCal, BearingUnit.Degrees); |
| 187 |
liveSeries.setClinoCalibration(clinoCal, GradientUnit.Degrees); |
| 188 |
liveSeries.setDeclination(declinationCal); |
| 189 |
liveSeries.setDataOrder(dataOrder); |
| 190 |
|
| 191 |
DataBlockProperties newBlock = new DataBlockProperties( blockProps ); |
| 192 |
|
| 193 |
blockProps = newBlock; |
| 194 |
} |
| 195 |
else if (data.length < 2) { |
| 196 |
|
| 197 |
DataBlockProperties newBlock = new DataBlockProperties( blockProps ); |
| 198 |
|
| 199 |
blockProps = newBlock; |
| 200 |
|
| 201 |
} |
| 202 |
else { |
| 203 |
|
| 204 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("BEGIN/END blocks names containing spaces are not supported.", lineRef ), lineNo ); |
| 205 |
} |
| 206 |
} |
| 207 |
else if ( cmd.compareToIgnoreCase("END") == 0 ) { |
| 208 |
|
| 209 |
if ( data.length == 1 ) { |
| 210 |
|
| 211 |
blockProps = blockProps.parentBlock; |
| 212 |
} |
| 213 |
else { |
| 214 |
|
| 215 |
String blockEndName = data[1]; |
| 216 |
|
| 217 |
String currentBlockName = nameStack.get( nameStack.size() - 1 ); |
| 218 |
if ( currentBlockName.compareToIgnoreCase(blockEndName) == 0 ) { |
| 219 |
|
| 220 |
|
| 221 |
SurveySeries endedSeries = seriesStack.remove( seriesStack.size() - 1 ); |
| 222 |
nameStack.remove( nameStack.size() - 1 ); |
| 223 |
|
| 224 |
blockProps = blockProps.parentBlock; |
| 225 |
if ( seriesStack.size() > 0) { |
| 226 |
|
| 227 |
liveSeries = seriesStack.get( seriesStack.size() - 1 ); |
| 228 |
liveSeries.addSeries( endedSeries ); |
| 229 |
|
| 230 |
state = 1; |
| 231 |
} |
| 232 |
else { |
| 233 |
|
| 234 |
allSeries.add( endedSeries ); |
| 235 |
|
| 236 |
liveSeries = null; |
| 237 |
|
| 238 |
state = 0; |
| 239 |
} |
| 240 |
} |
| 241 |
else { |
| 242 |
|
| 243 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Names of begin end blocks do not match. Begin=" + |
| 244 |
currentBlockName + " End=" + blockEndName + ".", lineRef ), lineNo ); |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
else if ( cmd.compareToIgnoreCase("EQUATE") == 0 ) { |
| 249 |
|
| 250 |
String fullSeriesPrefix = fullNestedSeriesName(nameStack); |
| 251 |
Equate equate = new Equate( fullSeriesPrefix, data[1], fullSeriesPrefix, data[2] ); |
| 252 |
|
| 253 |
equates.add(equate); |
| 254 |
} |
| 255 |
else if ( cmd.compareToIgnoreCase("DATA") == 0 ) { |
| 256 |
|
| 257 |
blockProps.noSurvey = false; |
| 258 |
|
| 259 |
if ( data[1].compareToIgnoreCase("PASSAGE") == 0 ) { |
| 260 |
|
| 261 |
state = 2; |
| 262 |
} |
| 263 |
else if ( data[1].compareToIgnoreCase("NORMAL") == 0 ) { |
| 264 |
state = 1; |
| 265 |
|
| 266 |
|
| 267 |
logger.logMessage( "Found normal data header at line " + lineNo + ". Checking format." ); |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
dataOrder.clear(); |
| 272 |
List<String> allOrderKeys = new ArrayList<String>(); |
| 273 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_FROMSTN ); |
| 274 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_TOSTN ); |
| 275 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_LENGTH ); |
| 276 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_BEARING ); |
| 277 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_CLINO ); |
| 278 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_IGNOREALL ); |
| 279 |
|
| 280 |
for (int dataIdx = 2; dataIdx < data.length; dataIdx++) { |
| 281 |
|
| 282 |
String item = data[dataIdx].toUpperCase(); |
| 283 |
if ( item.compareTo("TAPE") == 0 ) { |
| 284 |
item = CaveConverter.DATA_ORDER_CAT_LENGTH; |
| 285 |
} |
| 286 |
else if ( item.compareTo("COMPASS") == 0 ) { |
| 287 |
item = CaveConverter.DATA_ORDER_CAT_BEARING; |
| 288 |
} |
| 289 |
else if ( item.compareTo("CLINO") == 0 ) { |
| 290 |
item = CaveConverter.DATA_ORDER_CAT_CLINO; |
| 291 |
} |
| 292 |
|
| 293 |
int foundIdx = allOrderKeys.indexOf( item ); |
| 294 |
if ( foundIdx > -1 ) { |
| 295 |
|
| 296 |
dataOrder.add( item ); |
| 297 |
allOrderKeys.remove( foundIdx ); |
| 298 |
} |
| 299 |
else { |
| 300 |
|
| 301 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported survex normal data order. Term '" + item + "' is not supported.", lineRef ), lineNo ); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
List<String> checkDataOrder = liveSeries.getDataOrder(); |
| 307 |
if ( checkDataOrder.size() > 0 |
| 308 |
&& ( UtilityFunctions.dataOrderIsDiving( checkDataOrder ) ) ) { |
| 309 |
liveSeries.setDataOrder2(dataOrder); |
| 310 |
} |
| 311 |
else { |
| 312 |
liveSeries.setDataOrder(dataOrder); |
| 313 |
} |
| 314 |
} |
| 315 |
else if ( data[1].compareToIgnoreCase("DIVING") == 0 ) { |
| 316 |
state = 1; |
| 317 |
|
| 318 |
|
| 319 |
logger.logMessage( "Found diving data header at line " + lineNo + ". Checking format." ); |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
dataOrder.clear(); |
| 324 |
List<String> allOrderKeys = new ArrayList<String>(); |
| 325 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_FROMSTN ); |
| 326 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_TOSTN ); |
| 327 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_LENGTH ); |
| 328 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_BEARING ); |
| 329 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_FROMDEPTH ); |
| 330 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_TODEPTH ); |
| 331 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_DEPTHCHANGE ); |
| 332 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_IGNOREALL ); |
| 333 |
|
| 334 |
for (int dataIdx = 2; dataIdx < data.length; dataIdx++) { |
| 335 |
|
| 336 |
String item = data[dataIdx].toUpperCase(); |
| 337 |
if ( item.compareTo("TAPE") == 0 ) { |
| 338 |
item = CaveConverter.DATA_ORDER_CAT_LENGTH; |
| 339 |
} |
| 340 |
else if ( item.compareTo("COMPASS") == 0 ) { |
| 341 |
item = CaveConverter.DATA_ORDER_CAT_BEARING; |
| 342 |
} |
| 343 |
|
| 344 |
int foundIdx = allOrderKeys.indexOf( item ); |
| 345 |
if ( foundIdx > -1 ) { |
| 346 |
|
| 347 |
dataOrder.add( item ); |
| 348 |
allOrderKeys.remove( foundIdx ); |
| 349 |
|
| 350 |
if ( item.compareTo(CaveConverter.DATA_ORDER_CAT_DEPTHCHANGE) == 0 ) { |
| 351 |
|
| 352 |
int altIdx = allOrderKeys.indexOf( CaveConverter.DATA_ORDER_CAT_FROMDEPTH ); |
| 353 |
if ( altIdx > -1 ) { |
| 354 |
allOrderKeys.remove( altIdx ); |
| 355 |
} |
| 356 |
altIdx = allOrderKeys.indexOf( CaveConverter.DATA_ORDER_CAT_TODEPTH ); |
| 357 |
if ( altIdx > -1 ) { |
| 358 |
allOrderKeys.remove( altIdx ); |
| 359 |
} |
| 360 |
} |
| 361 |
else if ( item.compareTo(CaveConverter.DATA_ORDER_CAT_FROMDEPTH) == 0 ) { |
| 362 |
|
| 363 |
int altIdx = allOrderKeys.indexOf( CaveConverter.DATA_ORDER_CAT_DEPTHCHANGE ); |
| 364 |
if ( altIdx > -1 ) { |
| 365 |
allOrderKeys.remove( altIdx ); |
| 366 |
} |
| 367 |
|
| 368 |
altIdx = allOrderKeys.indexOf( CaveConverter.DATA_ORDER_CAT_TODEPTH ); |
| 369 |
if ( altIdx == -1 ) { |
| 370 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported survex diving data order. todepth before fromdepth is not supported.", lineRef ), lineNo ); |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
else { |
| 375 |
|
| 376 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported survex diving data order. Term '" + item + "' is not supported.", lineRef ), lineNo ); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
List<String> checkDataOrder = liveSeries.getDataOrder(); |
| 382 |
if ( checkDataOrder.size() > 0 |
| 383 |
&& ( UtilityFunctions.dataOrderIsDiving( checkDataOrder ) == false ) ) { |
| 384 |
liveSeries.setDataOrder2(dataOrder); |
| 385 |
} |
| 386 |
else { |
| 387 |
liveSeries.setDataOrder(dataOrder); |
| 388 |
} |
| 389 |
} |
| 390 |
else if ( data[1].compareToIgnoreCase("NOSURVEY") == 0 ) { |
| 391 |
state = 1; |
| 392 |
|
| 393 |
|
| 394 |
logger.logMessage( "Found nosurvey data header at line " + lineNo + ". Checking format." ); |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
dataOrder.clear(); |
| 399 |
List<String> allOrderKeys = new ArrayList<String>(); |
| 400 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_FROMSTN ); |
| 401 |
allOrderKeys.add( CaveConverter.DATA_ORDER_CAT_TOSTN ); |
| 402 |
|
| 403 |
for (int dataIdx = 2; dataIdx < data.length; dataIdx++) { |
| 404 |
|
| 405 |
String item = data[dataIdx].toUpperCase(); |
| 406 |
|
| 407 |
int foundIdx = allOrderKeys.indexOf( item ); |
| 408 |
if ( foundIdx > -1 ) { |
| 409 |
|
| 410 |
dataOrder.add( item ); |
| 411 |
allOrderKeys.remove( foundIdx ); |
| 412 |
} |
| 413 |
else { |
| 414 |
|
| 415 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported survex nosurvey data order. Term '" + item + "' is not supported.", lineRef ), lineNo ); |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
blockProps.noSurvey = true; |
| 420 |
} |
| 421 |
else { |
| 422 |
|
| 423 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported survex data command: " + data[1], lineRef ), lineNo ); |
| 424 |
} |
| 425 |
} |
| 426 |
else if ( cmd.compareToIgnoreCase("CALIBRATE") == 0 ) { |
| 427 |
|
| 428 |
if (data.length == 3) { |
| 429 |
String type = data[1]; |
| 430 |
double value = Double.parseDouble( data[2] ); |
| 431 |
if ( type.compareToIgnoreCase("tape") == 0 ) { |
| 432 |
|
| 433 |
liveSeries.setTapeCalibration(value, liveSeries.getLengthUnit() ); |
| 434 |
} |
| 435 |
else if ( type.compareToIgnoreCase("declination") == 0 ) { |
| 436 |
|
| 437 |
liveSeries.setDeclination(value); |
| 438 |
} |
| 439 |
else if ( type.compareToIgnoreCase("compass") == 0 ) { |
| 440 |
|
| 441 |
liveSeries.setCompassCalibration(value, liveSeries.getBearingUnit() ); |
| 442 |
} |
| 443 |
else if ( type.compareToIgnoreCase("clino") == 0 ) { |
| 444 |
|
| 445 |
liveSeries.setClinoCalibration(value, liveSeries.getGradientUnit() ); |
| 446 |
} |
| 447 |
|
| 448 |
} |
| 449 |
else { |
| 450 |
|
| 451 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("CALIBRATE command did not contain a single instrument type plus value.", lineRef ), lineNo ); |
| 452 |
} |
| 453 |
} |
| 454 |
else if ( cmd.compareToIgnoreCase("DATE") == 0 ) { |
| 455 |
|
| 456 |
if (data.length > 1) { |
| 457 |
Date value = UtilityFunctions.stringToDate(data[1], "yyyy.MM.dd"); |
| 458 |
liveSeries.setSurveyDate(value); |
| 459 |
} |
| 460 |
else { |
| 461 |
logger.logMessage( "DATE command without further data skipped for line: " + dataLine); |
| 462 |
} |
| 463 |
} |
| 464 |
else if ( cmd.compareToIgnoreCase("UNITS") == 0 ) { |
| 465 |
|
| 466 |
if ( data.length > 2 ) { |
| 467 |
|
| 468 |
int unitIdx = 0; |
| 469 |
for (int i = 2; i < data.length; i++) { |
| 470 |
if ( ( data[i].compareToIgnoreCase("METRES") == 0 ) |
| 471 |
|| ( data[i].compareToIgnoreCase("METERS") == 0 ) |
| 472 |
|| ( data[i].compareToIgnoreCase("METRIC") == 0 ) |
| 473 |
|| ( data[i].compareToIgnoreCase("YARDS") == 0 ) |
| 474 |
|| ( data[i].compareToIgnoreCase("FEET") == 0 ) |
| 475 |
|| ( data[i].compareToIgnoreCase("DEGS") == 0 ) |
| 476 |
|| ( data[i].compareToIgnoreCase("DEGREES") == 0 ) |
| 477 |
|| ( data[i].compareToIgnoreCase("GRADS") == 0 ) |
| 478 |
|| ( data[i].compareToIgnoreCase("MILS") == 0 ) |
| 479 |
|| ( data[i].compareToIgnoreCase("MINUTES") == 0 ) |
| 480 |
|| ( data[i].compareToIgnoreCase("PERCENT") == 0 ) |
| 481 |
|| ( data[i].compareToIgnoreCase("PERCENTAGE") == 0 ) ) { |
| 482 |
|
| 483 |
unitIdx = i; |
| 484 |
break; |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
if (unitIdx > 0) { |
| 489 |
for (int i = 1; i < unitIdx; i++) { |
| 490 |
if ( data[i].compareToIgnoreCase("TAPE") == 0 || data[i].compareToIgnoreCase("LENGTH") == 0 ) { |
| 491 |
|
| 492 |
if ( data[unitIdx].compareToIgnoreCase("METRES") == 0 || data[unitIdx].compareToIgnoreCase("METERS") == 0 || data[unitIdx].compareToIgnoreCase("METRIC") == 0 ) { |
| 493 |
liveSeries.setLengthUnit( LengthUnit.Metres ); |
| 494 |
} |
| 495 |
else if ( data[unitIdx].compareToIgnoreCase("FEET") == 0 ) { |
| 496 |
liveSeries.setLengthUnit( LengthUnit.Feet ); |
| 497 |
} |
| 498 |
else if ( data[unitIdx].compareToIgnoreCase("YARDS") == 0 ) { |
| 499 |
liveSeries.setLengthUnit( LengthUnit.Yards ); |
| 500 |
} |
| 501 |
else { |
| 502 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported length unit '" + data[unitIdx] + "'.", lineRef ), lineNo ); |
| 503 |
} |
| 504 |
} |
| 505 |
else if ( data[i].compareToIgnoreCase("DEPTH") == 0 ) { |
| 506 |
|
| 507 |
if ( data[unitIdx].compareToIgnoreCase("METRES") == 0 || data[unitIdx].compareToIgnoreCase("METERS") == 0 || data[unitIdx].compareToIgnoreCase("METRIC") == 0 ) { |
| 508 |
liveSeries.setDepthUnit( LengthUnit.Metres ); |
| 509 |
} |
| 510 |
else if ( data[unitIdx].compareToIgnoreCase("FEET") == 0 ) { |
| 511 |
liveSeries.setDepthUnit( LengthUnit.Feet ); |
| 512 |
} |
| 513 |
else if ( data[unitIdx].compareToIgnoreCase("YARDS") == 0 ) { |
| 514 |
liveSeries.setDepthUnit( LengthUnit.Yards ); |
| 515 |
} |
| 516 |
else { |
| 517 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported depth unit '" + data[unitIdx] + "'.", lineRef ), lineNo ); |
| 518 |
} |
| 519 |
} |
| 520 |
else if ( data[i].compareToIgnoreCase("COMPASS") == 0 || data[i].compareToIgnoreCase("BEARING") == 0 ) { |
| 521 |
|
| 522 |
if ( data[unitIdx].compareToIgnoreCase("DEGS") == 0 || data[unitIdx].compareToIgnoreCase("DEGREES") == 0 ) { |
| 523 |
liveSeries.setBearingUnit( BearingUnit.Degrees ); |
| 524 |
} |
| 525 |
else if ( data[unitIdx].compareToIgnoreCase("GRADS") == 0 || data[unitIdx].compareToIgnoreCase("MILS") == 0 ) { |
| 526 |
liveSeries.setBearingUnit( BearingUnit.Grads ); |
| 527 |
} |
| 528 |
else if ( data[unitIdx].compareToIgnoreCase("MINUTES") == 0 ) { |
| 529 |
liveSeries.setBearingUnit( BearingUnit.Minutes ); |
| 530 |
} |
| 531 |
else { |
| 532 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported bearing unit '" + data[unitIdx] + "'.", lineRef ), lineNo ); |
| 533 |
} |
| 534 |
} |
| 535 |
else if ( data[i].compareToIgnoreCase("CLINO") == 0 || data[i].compareToIgnoreCase("GRADIENT") == 0 ) { |
| 536 |
|
| 537 |
if ( data[unitIdx].compareToIgnoreCase("DEGS") == 0 || data[unitIdx].compareToIgnoreCase("DEGREES") == 0 ) { |
| 538 |
liveSeries.setGradientUnit( GradientUnit.Degrees ); |
| 539 |
} |
| 540 |
else if ( data[unitIdx].compareToIgnoreCase("GRADS") == 0 || data[unitIdx].compareToIgnoreCase("MILS") == 0 ) { |
| 541 |
liveSeries.setGradientUnit( GradientUnit.Grads ); |
| 542 |
} |
| 543 |
else if ( data[unitIdx].compareToIgnoreCase("PERCENT") == 0 || data[unitIdx].compareToIgnoreCase("PERCENTAGE") == 0 ) { |
| 544 |
liveSeries.setGradientUnit( GradientUnit.Percent ); |
| 545 |
} |
| 546 |
else if ( data[unitIdx].compareToIgnoreCase("MINUTES") == 0 ) { |
| 547 |
liveSeries.setGradientUnit( GradientUnit.Minutes ); |
| 548 |
} |
| 549 |
else { |
| 550 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported gradient unit '" + data[unitIdx] + "'.", lineRef ), lineNo ); |
| 551 |
} |
| 552 |
} |
| 553 |
else { |
| 554 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Unsupported unit type '" + data[i] + "'.", lineRef ), lineNo ); |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
else { |
| 559 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("UNITS command did not contain a category of measurement plus value.", lineRef ), lineNo ); |
| 560 |
} |
| 561 |
|
| 562 |
} |
| 563 |
|
| 564 |
} |
| 565 |
else if ( cmd.compareToIgnoreCase("FLAGS") == 0 ) { |
| 566 |
|
| 567 |
boolean notPrefixed = false; |
| 568 |
for (int iFlags = 1; iFlags < data.length; iFlags++) { |
| 569 |
|
| 570 |
if (data[iFlags].compareToIgnoreCase("NOT") == 0 ) { |
| 571 |
notPrefixed = true; |
| 572 |
} |
| 573 |
else if (data[iFlags].compareToIgnoreCase("DUPLICATE") == 0 ) { |
| 574 |
blockProps.duplicateFlag = (notPrefixed == false); |
| 575 |
notPrefixed = false; |
| 576 |
} |
| 577 |
else if (data[iFlags].compareToIgnoreCase("SPLAY") == 0 ) { |
| 578 |
blockProps.splayFlag = (notPrefixed == false); |
| 579 |
notPrefixed = false; |
| 580 |
} |
| 581 |
else if (data[iFlags].compareToIgnoreCase("SURFACE") == 0 ) { |
| 582 |
blockProps.surfaceFlag = (notPrefixed == false); |
| 583 |
notPrefixed = false; |
| 584 |
} |
| 585 |
else { |
| 586 |
|
| 587 |
notPrefixed = false; |
| 588 |
} |
| 589 |
} |
| 590 |
} |
| 591 |
else { |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
logger.logMessage("Unsupported Survex command ignored: " + cmd); |
| 597 |
} |
| 598 |
} |
| 599 |
else { |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
if ( liveSeries != null ) { |
| 604 |
|
| 605 |
String[] data = UtilityFunctions.cleanAndSplitDataLine(dataLine); |
| 606 |
|
| 607 |
switch (state) { |
| 608 |
case 1: |
| 609 |
|
| 610 |
SurveyLeg leg = new SurveyLeg(); |
| 611 |
double fromDepth = 0; |
| 612 |
|
| 613 |
|
| 614 |
int index = 0; |
| 615 |
while ( index < data.length ) { |
| 616 |
String item = data[index]; |
| 617 |
|
| 618 |
if ( item.charAt(0) == ';' ) { |
| 619 |
|
| 620 |
|
| 621 |
index = data.length; |
| 622 |
} |
| 623 |
else { |
| 624 |
|
| 625 |
if ( dataOrder.size() == 0 ) { |
| 626 |
|
| 627 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_FROMSTN ); |
| 628 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_TOSTN ); |
| 629 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_LENGTH ); |
| 630 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_BEARING ); |
| 631 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_CLINO ); |
| 632 |
} |
| 633 |
else if ( blockProps.noSurvey == false && dataOrder.size() <5 ) { |
| 634 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Last data order command did not contain enough items for a survey leg.", lineRef ), lineNo ); |
| 635 |
} |
| 636 |
else if ( ( dataOrder.size() < index + 1 ) |
| 637 |
&& ( dataOrder.get( dataOrder.size() - 1 ).equals( CaveConverter.DATA_ORDER_CAT_IGNOREALL ) ) == false ) { |
| 638 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Last data order command did not contain enough items for data line.", lineRef ), lineNo ); |
| 639 |
} |
| 640 |
|
| 641 |
String itemCat = CaveConverter.DATA_ORDER_CAT_IGNOREALL; |
| 642 |
if ( index < dataOrder.size() ) { |
| 643 |
itemCat = dataOrder.get( index ); |
| 644 |
} |
| 645 |
if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_FROMSTN ) ) { |
| 646 |
|
| 647 |
leg.setFromStn( UtilityFunctions.createStationFromNameForSeries( data[index], liveSeries ) ); |
| 648 |
|
| 649 |
if ( blockProps.noSurvey ) { |
| 650 |
leg.setNosurvey( true ); |
| 651 |
} |
| 652 |
} |
| 653 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_TOSTN ) ) { |
| 654 |
|
| 655 |
leg.setToStn( UtilityFunctions.createStationFromNameForSeries( data[index], liveSeries ) ); |
| 656 |
} |
| 657 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_LENGTH ) ) { |
| 658 |
double length = Double.parseDouble( data[index] ); |
| 659 |
if ( length < 0 ) { |
| 660 |
logger.logMessage("Warning: Negative leg length (" + data[index] + |
| 661 |
") read from Survex file at line " + lineNo + "."); |
| 662 |
} |
| 663 |
leg.setLength( length, liveSeries.getLengthUnit() ); |
| 664 |
} |
| 665 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_BEARING ) ) { |
| 666 |
if ( data[index].compareTo("-") == 0 ) { |
| 667 |
leg.setCompass( 0, BearingUnit.Degrees ); |
| 668 |
} |
| 669 |
else { |
| 670 |
leg.setCompass( Double.valueOf( data[index] ), liveSeries.getBearingUnit() ); |
| 671 |
} |
| 672 |
} |
| 673 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_CLINO ) ) { |
| 674 |
|
| 675 |
String val = data[index]; |
| 676 |
int commentCharPos = val.indexOf(';'); |
| 677 |
if ( commentCharPos > 0 ) { |
| 678 |
val = val.substring(0, commentCharPos); |
| 679 |
} |
| 680 |
double straightDown = -90; |
| 681 |
double straightUp = 90; |
| 682 |
double level = 0; |
| 683 |
if ( val.compareToIgnoreCase("-V") == 0 ) { |
| 684 |
leg.setClino( straightDown, GradientUnit.Degrees ); |
| 685 |
} |
| 686 |
else if ( val.compareToIgnoreCase("down") == 0 ) { |
| 687 |
leg.setClino( straightDown, GradientUnit.Degrees ); |
| 688 |
} |
| 689 |
else if ( val.compareToIgnoreCase("d") == 0 ) { |
| 690 |
leg.setClino( straightDown, GradientUnit.Degrees ); |
| 691 |
} |
| 692 |
else if ( val.compareToIgnoreCase("+V") == 0 ) { |
| 693 |
leg.setClino( straightUp, GradientUnit.Degrees ); |
| 694 |
} |
| 695 |
else if ( val.compareToIgnoreCase("up") == 0 ) { |
| 696 |
leg.setClino( straightUp, GradientUnit.Degrees ); |
| 697 |
} |
| 698 |
else if ( val.compareToIgnoreCase("u") == 0 ) { |
| 699 |
leg.setClino( straightUp, GradientUnit.Degrees ); |
| 700 |
} |
| 701 |
else if ( val.compareToIgnoreCase("-") == 0 ) { |
| 702 |
leg.setClino( level, GradientUnit.Degrees ); |
| 703 |
} |
| 704 |
else if ( val.compareToIgnoreCase("level") == 0 ) { |
| 705 |
leg.setClino( level, GradientUnit.Degrees ); |
| 706 |
} |
| 707 |
else { |
| 708 |
leg.setClino( Double.valueOf( val ), liveSeries.getGradientUnit() ); |
| 709 |
} |
| 710 |
} |
| 711 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_FROMDEPTH ) ) { |
| 712 |
|
| 713 |
fromDepth = Double.parseDouble( data[index] ); |
| 714 |
} |
| 715 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_TODEPTH ) ) { |
| 716 |
double toDepth = Double.parseDouble( data[index] ); |
| 717 |
leg.setDepths( fromDepth, toDepth, liveSeries.getDepthUnit() ); |
| 718 |
} |
| 719 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_DEPTHCHANGE ) ) { |
| 720 |
double depthChange = Double.parseDouble( data[index] ); |
| 721 |
leg.setDepthChange( depthChange, liveSeries.getDepthUnit() ); |
| 722 |
} |
| 723 |
else if ( itemCat.equals( CaveConverter.DATA_ORDER_CAT_IGNOREALL ) ) { |
| 724 |
|
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
index++; |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
if ( blockProps.noSurvey || leg.getLength( LengthUnit.Metres ) > -1 ) { |
| 733 |
|
| 734 |
leg.setDuplicate(blockProps.duplicateFlag); |
| 735 |
leg.setSplay(blockProps.splayFlag); |
| 736 |
leg.setSurface(blockProps.surfaceFlag); |
| 737 |
|
| 738 |
liveSeries.addLeg(leg); |
| 739 |
} |
| 740 |
break; |
| 741 |
case 2: |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
break; |
| 752 |
} |
| 753 |
|
| 754 |
} |
| 755 |
else { |
| 756 |
|
| 757 |
throw new ParseException( UtilityFunctions.formatFileParserMsg("Data line found outside of any begin/end block.", lineRef ), lineNo ); |
| 758 |
} |
| 759 |
|
| 760 |
} |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
UtilityFunctions.processEquates(equates, allSeries); |
| 766 |
|
| 767 |
|
| 768 |
UtilityFunctions.logSurveyDebugData(allSeries, logger); |
| 769 |
|
| 770 |
|
| 771 |
return allSeries; |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
private String fullNestedSeriesName(List<String> stack) { |
| 776 |
String name = ""; |
| 777 |
|
| 778 |
Iterator<String> stackIterator = stack.listIterator(); |
| 779 |
while ( stackIterator.hasNext() ) { |
| 780 |
name += "." + stackIterator.next(); |
| 781 |
} |
| 782 |
|
| 783 |
return name.substring(1); |
| 784 |
} |
| 785 |
|
| 786 |
} |