| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.tools; |
| 20 |
|
| 21 |
import java.io.BufferedReader; |
| 22 |
import java.io.BufferedWriter; |
| 23 |
import java.io.File; |
| 24 |
import java.io.FileInputStream; |
| 25 |
import java.io.FileNotFoundException; |
| 26 |
import java.io.FileOutputStream; |
| 27 |
import java.io.IOException; |
| 28 |
import java.io.InputStreamReader; |
| 29 |
import java.io.OutputStreamWriter; |
| 30 |
import java.io.Writer; |
| 31 |
import java.text.ParseException; |
| 32 |
import java.text.SimpleDateFormat; |
| 33 |
import java.util.ArrayList; |
| 34 |
import java.util.Arrays; |
| 35 |
import java.util.Calendar; |
| 36 |
import java.util.Date; |
| 37 |
import java.util.Iterator; |
| 38 |
import java.util.List; |
| 39 |
import java.util.ListIterator; |
| 40 |
import java.util.TimeZone; |
| 41 |
|
| 42 |
import footleg.cavesurvey.converter.CaveConverter.BearingUnit; |
| 43 |
import footleg.cavesurvey.converter.CaveConverter.GradientUnit; |
| 44 |
import footleg.cavesurvey.converter.CaveConverter.LengthUnit; |
| 45 |
import footleg.cavesurvey.converter.CaveConverter.SurveyDataInputFormats; |
| 46 |
import footleg.cavesurvey.converter.CaveConverter.SurveyDataOutputFormats; |
| 47 |
import footleg.cavesurvey.converter.Logger; |
| 48 |
import footleg.cavesurvey.data.model.CaveSurvey; |
| 49 |
import footleg.cavesurvey.data.model.Equate; |
| 50 |
import footleg.cavesurvey.data.model.SurveyLeg; |
| 51 |
import footleg.cavesurvey.data.model.SurveySeries; |
| 52 |
import footleg.cavesurvey.data.model.SurveyStation; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public final class UtilityFunctions { |
| 62 |
private static final double feetPerMetre = 3.280839895; |
| 63 |
|
| 64 |
private static final char compassFormat = 'c'; |
| 65 |
private static final char dxfFormat = 'd'; |
| 66 |
private static final char pocketTopoFormat = 'p'; |
| 67 |
private static final char survexFormat = 's'; |
| 68 |
private static final char toporobotFormat = 't'; |
| 69 |
|
| 70 |
public static final String POCKETTOPO_DATE_FORMAT = "yyyy/MM/dd"; |
| 71 |
public static final String SURVEXDATE_FORMAT = "yyyy.MM.dd"; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public static SurveyDataInputFormats inputDataFormatFromLetterCode( char letterCode ) throws ParseException { |
| 81 |
SurveyDataInputFormats format = null; |
| 82 |
|
| 83 |
switch (letterCode) { |
| 84 |
case compassFormat: |
| 85 |
format = SurveyDataInputFormats.Compass; |
| 86 |
break; |
| 87 |
case dxfFormat: |
| 88 |
format = SurveyDataInputFormats.DXF; |
| 89 |
break; |
| 90 |
case pocketTopoFormat: |
| 91 |
format = SurveyDataInputFormats.PocketTopo; |
| 92 |
break; |
| 93 |
case survexFormat: |
| 94 |
format = SurveyDataInputFormats.Survex; |
| 95 |
break; |
| 96 |
default: |
| 97 |
|
| 98 |
ParseException e = new ParseException("Unknown data format letter code: " + |
| 99 |
letterCode + "'.", 1); |
| 100 |
throw e; |
| 101 |
} |
| 102 |
|
| 103 |
return format; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public static SurveyDataOutputFormats outputDataFormatFromLetterCode( char letterCode ) throws ParseException { |
| 114 |
SurveyDataOutputFormats format = null; |
| 115 |
|
| 116 |
switch (letterCode) { |
| 117 |
case survexFormat: |
| 118 |
format = SurveyDataOutputFormats.Survex; |
| 119 |
break; |
| 120 |
case toporobotFormat: |
| 121 |
format = SurveyDataOutputFormats.Toporobot; |
| 122 |
break; |
| 123 |
default: |
| 124 |
|
| 125 |
ParseException e = new ParseException("Unknown data format letter code: " + |
| 126 |
letterCode + "'.", 1); |
| 127 |
throw e; |
| 128 |
} |
| 129 |
|
| 130 |
return format; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public static double averageCompassBearings( double[] bearings ) { |
| 154 |
double meanBearing = 0.0; |
| 155 |
|
| 156 |
double accumulatorCos = 0.0; |
| 157 |
double accumulatorSin = 0.0; |
| 158 |
|
| 159 |
|
| 160 |
for ( int bearingIdx = 0; bearingIdx < bearings.length; bearingIdx++ ) { |
| 161 |
|
| 162 |
Double bearing = Math.toRadians( bearings[bearingIdx] ); |
| 163 |
|
| 164 |
|
| 165 |
accumulatorCos += Math.cos(bearing); |
| 166 |
accumulatorSin += Math.sin(bearing); |
| 167 |
} |
| 168 |
|
| 169 |
double average_angle_atan2 = Math.atan2(accumulatorSin, accumulatorCos); |
| 170 |
meanBearing = Math.toDegrees(average_angle_atan2); |
| 171 |
|
| 172 |
|
| 173 |
return adjustBearingWithinDegreesRange( meanBearing, 0, 360 ); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public static double adjustBearingWithinDegreesRange(double bearing, double min, double max) { |
| 184 |
double adjustedBearing = bearing; |
| 185 |
|
| 186 |
while ( adjustedBearing < min ) { |
| 187 |
adjustedBearing += 360; |
| 188 |
} |
| 189 |
while ( adjustedBearing >= max ) { |
| 190 |
adjustedBearing -= 360; |
| 191 |
} |
| 192 |
|
| 193 |
return adjustedBearing; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public static double bearingDifferenceDegrees( double angle1, double angle2) { |
| 203 |
double dif = Math.abs( angle1 - angle2 ) % 360; |
| 204 |
|
| 205 |
if (dif > 180) |
| 206 |
dif = 360 - dif; |
| 207 |
return dif; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
public static SurveyStation createStationFromNameForSeries( String stnName, SurveySeries series ) { |
| 222 |
SurveyStation stn = new SurveyStation( 0 ); |
| 223 |
stn.setName( stnName ); |
| 224 |
series.setStationIdFromName(stn); |
| 225 |
|
| 226 |
return stn; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
public static Date stringToDate( String dateString, String dateFormat ) throws ParseException { |
| 238 |
Date dateVal; |
| 239 |
|
| 240 |
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); |
| 241 |
sdf.setTimeZone(TimeZone.getDefault()); |
| 242 |
|
| 243 |
dateVal = sdf.parse(dateString); |
| 244 |
|
| 245 |
return dateVal; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
public static String dateToString( Date date, String dateFormat ) { |
| 256 |
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); |
| 257 |
sdf.setTimeZone(TimeZone.getDefault()); |
| 258 |
|
| 259 |
return sdf.format( date ); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public static String todaysDateAsString( String dateFormat ) { |
| 270 |
Calendar cal = Calendar.getInstance(TimeZone.getDefault()); |
| 271 |
Date dateTimeNow = cal.getTime(); |
| 272 |
|
| 273 |
return dateToString( dateTimeNow, dateFormat ); |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
public static String stringListToDotSeparatedString( List<String> list, String separator) { |
| 285 |
String items = ""; |
| 286 |
|
| 287 |
ListIterator<String> primaryIterator = list.listIterator(); |
| 288 |
if ( primaryIterator.hasNext() ) { |
| 289 |
|
| 290 |
items += primaryIterator.next(); |
| 291 |
} |
| 292 |
while ( primaryIterator.hasNext() ) { |
| 293 |
items += separator + primaryIterator.next(); |
| 294 |
} |
| 295 |
|
| 296 |
return items; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
public static List<String> parseDataStringIntoDataItems( String dataString ) { |
| 308 |
List<String> dataItems = new ArrayList<String>(); |
| 309 |
String currItem = ""; |
| 310 |
boolean insideQuotes = false; |
| 311 |
|
| 312 |
|
| 313 |
for (int i = 0; i < dataString.length(); i++) { |
| 314 |
|
| 315 |
if ( insideQuotes ) { |
| 316 |
|
| 317 |
if ( dataString.charAt(i) == '\"' ) { |
| 318 |
|
| 319 |
dataItems.add( currItem ); |
| 320 |
|
| 321 |
currItem = ""; |
| 322 |
insideQuotes = false; |
| 323 |
} |
| 324 |
else { |
| 325 |
|
| 326 |
currItem += dataString.charAt(i); |
| 327 |
} |
| 328 |
} |
| 329 |
else if ( dataString.charAt(i) == '\"' ) { |
| 330 |
|
| 331 |
insideQuotes = true; |
| 332 |
} |
| 333 |
else if ( dataString.charAt(i) == ' ' || dataString.charAt(i) == '\t' ) { |
| 334 |
|
| 335 |
if ( currItem.length() > 0 ) { |
| 336 |
|
| 337 |
dataItems.add( currItem ); |
| 338 |
|
| 339 |
currItem = ""; |
| 340 |
} |
| 341 |
} |
| 342 |
else { |
| 343 |
|
| 344 |
currItem += dataString.charAt(i); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
if ( currItem.length() > 0 ) { |
| 350 |
|
| 351 |
dataItems.add( currItem ); |
| 352 |
} |
| 353 |
|
| 354 |
return dataItems; |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
public static String[] parseTripComment( String comment ) { |
| 365 |
String dataString = comment.replace("\\r", "\r"); |
| 366 |
String[] dataItems = dataString.split("\r"); |
| 367 |
|
| 368 |
return dataItems; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
public static void processEquates( List<Equate> equates, CaveSurvey allSeries ) { |
| 383 |
|
| 384 |
Iterator<Equate> equateIterator = equates.listIterator(); |
| 385 |
while ( equateIterator.hasNext() ) { |
| 386 |
Equate equate = equateIterator.next(); |
| 387 |
|
| 388 |
|
| 389 |
String innerSeries; |
| 390 |
String outerSeries; |
| 391 |
String innerSeriesStn; |
| 392 |
String outerSeriesStn; |
| 393 |
|
| 394 |
if ( equate.getSeries1().length() > equate.getSeries2().length() ) { |
| 395 |
|
| 396 |
outerSeries = equate.getSeries2(); |
| 397 |
outerSeriesStn = equate.getStn2(); |
| 398 |
innerSeries = equate.getSeries1(); |
| 399 |
innerSeriesStn = equate.getStn1(); |
| 400 |
} |
| 401 |
else { |
| 402 |
|
| 403 |
outerSeries = equate.getSeries1(); |
| 404 |
outerSeriesStn = equate.getStn1(); |
| 405 |
innerSeries = equate.getSeries2(); |
| 406 |
innerSeriesStn = equate.getStn2(); |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
List<String> outerHierarchy = new ArrayList<String>(Arrays.asList(outerSeries.split("[.]"))); |
| 411 |
List<String> innerHierarchy = new ArrayList<String>(Arrays.asList(innerSeries.split("[.]"))); |
| 412 |
List<String> parentHierarchy = new ArrayList<String>(); |
| 413 |
|
| 414 |
boolean matching = true; |
| 415 |
while ( matching && (outerHierarchy.size() > 0 ) ) { |
| 416 |
if (outerHierarchy.get(0).equalsIgnoreCase( innerHierarchy.get(0) ) ) { |
| 417 |
|
| 418 |
parentHierarchy.add( outerHierarchy.remove(0) ); |
| 419 |
innerHierarchy.remove(0); |
| 420 |
} |
| 421 |
else { |
| 422 |
matching = false; |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
SurveySeries liveSeries = null; |
| 428 |
|
| 429 |
|
| 430 |
if ( parentHierarchy.size() > 0 ) { |
| 431 |
|
| 432 |
ListIterator<String> pathIterator = parentHierarchy.listIterator(); |
| 433 |
String liveName = pathIterator.next(); |
| 434 |
|
| 435 |
|
| 436 |
ListIterator<SurveySeries> primaryIterator = allSeries.listIterator(); |
| 437 |
while ( primaryIterator.hasNext() ) { |
| 438 |
SurveySeries outermostSeries = primaryIterator.next(); |
| 439 |
if ( outermostSeries.getSeriesName().equalsIgnoreCase( liveName ) ) { |
| 440 |
|
| 441 |
liveSeries = outermostSeries; |
| 442 |
break; |
| 443 |
} |
| 444 |
else { |
| 445 |
|
| 446 |
matching = false; |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
if ( liveSeries != null ) { |
| 452 |
|
| 453 |
if ( pathIterator.hasNext() ) { |
| 454 |
liveSeries = findInnerSeriesByName( liveSeries, pathIterator); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
matching = true; |
| 459 |
|
| 460 |
} |
| 461 |
else { |
| 462 |
|
| 463 |
throw new RuntimeException( "Equate series outer name '" + |
| 464 |
liveName + "' did not match any cave name." ); |
| 465 |
} |
| 466 |
|
| 467 |
} |
| 468 |
else { |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
throw new RuntimeException( "Series in equate did not match any series name. Series1: '" + |
| 474 |
equate.getSeries1() + "'. Series2: '" + equate.getSeries2() + "'." ); |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
if ( liveSeries != null ) { |
| 502 |
String equatePart1; |
| 503 |
SurveySeries part1Series; |
| 504 |
SurveyStation stn1 = null; |
| 505 |
if ( outerHierarchy.isEmpty() ) { |
| 506 |
equatePart1 = ""; |
| 507 |
part1Series = liveSeries; |
| 508 |
stn1 = createStationFromNameForSeries( outerSeriesStn, part1Series ); |
| 509 |
} |
| 510 |
else { |
| 511 |
equatePart1 = stringListToDotSeparatedString( outerHierarchy, "."); |
| 512 |
try { |
| 513 |
part1Series = findInnerSeriesByName( liveSeries, outerHierarchy.listIterator() ); |
| 514 |
stn1 = createStationFromNameForSeries( outerSeriesStn, part1Series ); |
| 515 |
} |
| 516 |
catch (RuntimeException ex) { |
| 517 |
|
| 518 |
stn1 = new SurveyStation( 0 ); |
| 519 |
stn1.setName( equate.getStn1() ); |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
String equatePart2; |
| 524 |
SurveySeries part2Series; |
| 525 |
SurveyStation stn2 = null; |
| 526 |
if ( innerHierarchy.isEmpty() ) { |
| 527 |
equatePart2 = ""; |
| 528 |
part2Series = liveSeries; |
| 529 |
stn2 = createStationFromNameForSeries( innerSeriesStn, part2Series ); |
| 530 |
} |
| 531 |
else { |
| 532 |
equatePart2 = stringListToDotSeparatedString( innerHierarchy, "."); |
| 533 |
try { |
| 534 |
part2Series = findInnerSeriesByName( liveSeries, innerHierarchy.listIterator() ); |
| 535 |
stn2 = createStationFromNameForSeries( innerSeriesStn, part2Series ); |
| 536 |
} |
| 537 |
catch (RuntimeException ex) { |
| 538 |
|
| 539 |
stn2 = new SurveyStation( 0 ); |
| 540 |
stn2.setName( equate.getStn2() ); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
liveSeries.addLink(equatePart1, stn1, equatePart2, stn2); |
| 546 |
} |
| 547 |
else { |
| 548 |
|
| 549 |
throw new RuntimeException( "Equate series are not inside same series. Series1: '" + |
| 550 |
equate.getSeries1() + "'. Series2: '" + equate.getSeries2() + "'." ); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
private static SurveySeries findInnerSeriesByName( SurveySeries outerSeries, ListIterator<String> pathIterator) { |
| 563 |
SurveySeries liveSeries = outerSeries; |
| 564 |
|
| 565 |
while ( pathIterator.hasNext() ) { |
| 566 |
String liveName = pathIterator.next(); |
| 567 |
liveSeries = liveSeries.findInnerSeriesByName( liveName ); |
| 568 |
if (liveSeries == null ) { |
| 569 |
|
| 570 |
throw new RuntimeException( "Equate series name '" + |
| 571 |
liveName + "' did not match any inner series name." ); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
return liveSeries; |
| 576 |
} |
| 577 |
|
| 578 |
public static void logSurveyDebugData( CaveSurvey allSeries, Logger logger ) { |
| 579 |
|
| 580 |
logger.logMessage("============================ Cave Survey Data Summary ============================"); |
| 581 |
logger.logMessage("Survey contains " + allSeries.size() + " top level series."); |
| 582 |
for (int i = 0; i < allSeries.size(); i++ ) { |
| 583 |
logSurveySeriesSummary( allSeries.get(i), "", logger ); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
private static void logSurveySeriesSummary( SurveySeries series, String seriesParent, Logger logger ) { |
| 588 |
String fullSeriesPath = seriesParent + series.getSeriesName(); |
| 589 |
String message = "Series: " + fullSeriesPath; |
| 590 |
if ( series.legCount() > 0 ) { |
| 591 |
message += " (" + series.legCount() + " legs)"; |
| 592 |
} |
| 593 |
if ( series.innerSeriesCount() > 0 ) { |
| 594 |
message += " (contains " + series.innerSeriesCount() + " child series)"; |
| 595 |
} |
| 596 |
logger.logMessage( message ); |
| 597 |
|
| 598 |
for (int i = 0; i < series.innerSeriesCount(); i++ ) { |
| 599 |
logSurveySeriesSummary( series.getInnerSeries(i), fullSeriesPath + "/", logger ); |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
public static List<String> readTextFile( File inputFile, String characterSetEncoding, |
| 618 |
boolean multiFile, List<String> multifileLineRefs, Logger logger ) { |
| 619 |
List<String> dataLines = new ArrayList<String>(); |
| 620 |
|
| 621 |
BufferedReader bufferedReader = null; |
| 622 |
|
| 623 |
try { |
| 624 |
FileInputStream fis = new FileInputStream( inputFile ); |
| 625 |
InputStreamReader isr = new InputStreamReader( fis, characterSetEncoding ); |
| 626 |
bufferedReader = new BufferedReader ( isr ); |
| 627 |
|
| 628 |
String text; |
| 629 |
int lineNo = 0; |
| 630 |
while ( ( text = bufferedReader.readLine() ) != null) { |
| 631 |
lineNo++; |
| 632 |
boolean addLine = true; |
| 633 |
|
| 634 |
if ( multiFile ) { |
| 635 |
|
| 636 |
String line = text.trim(); |
| 637 |
if ( line.toLowerCase().startsWith( "*include" ) ) { |
| 638 |
|
| 639 |
String pathAddn = ""; |
| 640 |
for ( int i = 8; i < line.length(); i++ ) { |
| 641 |
|
| 642 |
if ( line.charAt(i) == ';' ) { |
| 643 |
break; |
| 644 |
} |
| 645 |
else { |
| 646 |
pathAddn += line.charAt(i); |
| 647 |
} |
| 648 |
} |
| 649 |
pathAddn = pathAddn.trim(); |
| 650 |
|
| 651 |
if ( pathAddn.charAt(0) == '"' && pathAddn.charAt( pathAddn.length() - 1 ) == '"' ) { |
| 652 |
pathAddn = pathAddn.substring(1, pathAddn.length() - 1 ); |
| 653 |
} |
| 654 |
boolean extPresent = (pathAddn.lastIndexOf('.') >= 0) |
| 655 |
&& pathAddn.substring( pathAddn.lastIndexOf('.') ).toLowerCase().equals(".svx"); |
| 656 |
String nextFilePath = folderFromFile( inputFile ); |
| 657 |
File nextFile = new File( nextFilePath + File.separatorChar + pathAddn ); |
| 658 |
if ( extPresent == false && nextFile.exists() == false ) { |
| 659 |
|
| 660 |
nextFile = new File( nextFilePath + File.separatorChar + pathAddn + ".svx" ); |
| 661 |
if ( nextFile.exists() == false ) { |
| 662 |
|
| 663 |
nextFile = new File( nextFilePath + File.separatorChar + pathAddn + ".SVX" ); |
| 664 |
} |
| 665 |
} |
| 666 |
logger.logMessage( "Including file: " + nextFile.getPath() ); |
| 667 |
List<String> fileData = UtilityFunctions.readTextFile( nextFile, characterSetEncoding, multiFile, |
| 668 |
multifileLineRefs, logger ); |
| 669 |
dataLines.addAll(fileData); |
| 670 |
addLine = false; |
| 671 |
} |
| 672 |
else { |
| 673 |
|
| 674 |
multifileLineRefs.add( inputFile.getPath() + ":" + lineNo ); |
| 675 |
} |
| 676 |
} |
| 677 |
if ( addLine ) { |
| 678 |
dataLines.add( text ); |
| 679 |
} |
| 680 |
} |
| 681 |
} |
| 682 |
catch (FileNotFoundException ex) { |
| 683 |
logger.logError( ex.getMessage() ); |
| 684 |
} |
| 685 |
catch (IOException ex) { |
| 686 |
logger.logError( ex.getMessage() ); |
| 687 |
} |
| 688 |
finally { |
| 689 |
if ( bufferedReader != null ) { |
| 690 |
try { |
| 691 |
bufferedReader.close(); |
| 692 |
} catch (IOException ex) { |
| 693 |
logger.logError( ex.getMessage() ); |
| 694 |
} |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
return dataLines; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
public static String writeTextFile (List<String> fileContents, String fileName, String characterSetEncoding ) { |
| 711 |
String error = ""; |
| 712 |
|
| 713 |
BufferedWriter textWriter = null; |
| 714 |
try { |
| 715 |
|
| 716 |
FileOutputStream fos = new FileOutputStream( fileName ); |
| 717 |
Writer out = new OutputStreamWriter(fos, characterSetEncoding); |
| 718 |
textWriter = new BufferedWriter(out); |
| 719 |
|
| 720 |
|
| 721 |
Iterator<String> iterator = fileContents.listIterator(); |
| 722 |
while ( iterator.hasNext() ) { |
| 723 |
String line = iterator.next(); |
| 724 |
if ( iterator.hasNext() ) { |
| 725 |
textWriter.write( line + System.getProperty("line.separator") ); |
| 726 |
} |
| 727 |
else { |
| 728 |
textWriter.write( line ); |
| 729 |
} |
| 730 |
} |
| 731 |
} |
| 732 |
catch (IOException ex) { |
| 733 |
error = "Error writing file: " + ex.getLocalizedMessage(); |
| 734 |
} |
| 735 |
finally { |
| 736 |
if ( textWriter != null ) { |
| 737 |
try { |
| 738 |
textWriter.close(); |
| 739 |
} |
| 740 |
catch (IOException ex) { |
| 741 |
error = "Error closing file: " + ex.getLocalizedMessage(); |
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
return error; |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
private static boolean checkForLoopback( ListIterator<SurveyStation> iter, SurveyStation checkStn ) { |
| 757 |
boolean loopDetected = false; |
| 758 |
|
| 759 |
while ( iter.hasNext() ) { |
| 760 |
if ( checkStn.getId() == iter.next().getId() ) { |
| 761 |
loopDetected = true; |
| 762 |
break; |
| 763 |
} |
| 764 |
|
| 765 |
} |
| 766 |
return loopDetected; |
| 767 |
} |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
private static boolean checkForCrossover( SurveySeries caveSoFar, SurveyStation checkStn ) { |
| 776 |
boolean crossingDetected = false; |
| 777 |
|
| 778 |
ListIterator<SurveySeries> seriesIter = caveSoFar.getInnerSeriesList().listIterator(); |
| 779 |
while ( seriesIter.hasNext() ) { |
| 780 |
|
| 781 |
SurveySeries series = seriesIter.next(); |
| 782 |
for ( int i=0; i < series.legCount() - 1; i++ ) { |
| 783 |
SurveyLeg leg = series.getLegRaw(i); |
| 784 |
|
| 785 |
|
| 786 |
if ( checkStn.getId() == leg.getToStn().getId() ) { |
| 787 |
crossingDetected = true; |
| 788 |
i = series.legCount(); |
| 789 |
} |
| 790 |
} |
| 791 |
if ( crossingDetected == true ) { |
| 792 |
break; |
| 793 |
} |
| 794 |
} |
| 795 |
return crossingDetected; |
| 796 |
} |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
public static SurveySeries convertToLinearSeries( SurveySeries seriesIn, Logger logger ) { |
| 818 |
|
| 819 |
|
| 820 |
SurveySeries outputSeries = new SurveySeries( seriesIn.getSeriesName() ); |
| 821 |
|
| 822 |
|
| 823 |
if ( seriesIn.innerSeriesCount() > 0 ) { |
| 824 |
throw new RuntimeException( "Nested series cannot be converted to linear chains." ); |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
boolean legsRemain = true; |
| 830 |
while (legsRemain) { |
| 831 |
|
| 832 |
SurveySeries series = new SurveySeries( seriesIn.getSeriesName() ); |
| 833 |
series.setCalibrationFromAnotherSeries( seriesIn ); |
| 834 |
|
| 835 |
|
| 836 |
List<SurveyStation> seriesStns = new ArrayList<SurveyStation>(); |
| 837 |
|
| 838 |
|
| 839 |
int lastStnId = -999; |
| 840 |
|
| 841 |
|
| 842 |
int addedLegsCount = 0; |
| 843 |
boolean legsAdded = true; |
| 844 |
|
| 845 |
while ( legsAdded ) { |
| 846 |
legsAdded = false; |
| 847 |
|
| 848 |
int i = 0; |
| 849 |
while ( i < seriesIn.legCount() ) { |
| 850 |
int initialInnerAddedLegCount = addedLegsCount; |
| 851 |
SurveyLeg curLeg = seriesIn.getLegRaw(i); |
| 852 |
|
| 853 |
|
| 854 |
if ( ( series.legCount() == 0 ) || ( lastStnId == curLeg.getFromStn().getId() ) ) { |
| 855 |
|
| 856 |
boolean loopDetected = checkForLoopback( seriesStns.listIterator(), curLeg.getToStn() ); |
| 857 |
if (loopDetected == false) { |
| 858 |
boolean crossDetected = false; |
| 859 |
if ( series.legCount() > 0 ) { |
| 860 |
|
| 861 |
crossDetected = checkForCrossover( outputSeries, curLeg.getFromStn() ); |
| 862 |
} |
| 863 |
if (crossDetected == false) { |
| 864 |
|
| 865 |
series.addLeg(curLeg); |
| 866 |
|
| 867 |
lastStnId = curLeg.getToStn().getId(); |
| 868 |
|
| 869 |
addedLegsCount++; |
| 870 |
|
| 871 |
seriesStns.add( curLeg.getToStn() ); |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
else if ( curLeg.getToStn().getId() == series.getLegRaw(0).getFromStn().getId() ) { |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
boolean loopDetected = checkForLoopback( seriesStns.listIterator(), curLeg.getFromStn() ); |
| 880 |
if (loopDetected == false) { |
| 881 |
boolean crossDetected = checkForCrossover( outputSeries, curLeg.getToStn() ); |
| 882 |
if (crossDetected == false) { |
| 883 |
series.addLeg(curLeg, 0); |
| 884 |
|
| 885 |
addedLegsCount++; |
| 886 |
|
| 887 |
seriesStns.add( curLeg.getFromStn() ); |
| 888 |
} |
| 889 |
} |
| 890 |
} |
| 891 |
|
| 892 |
if (initialInnerAddedLegCount < addedLegsCount ) { |
| 893 |
|
| 894 |
seriesIn.removeLeg(i); |
| 895 |
|
| 896 |
legsAdded = true; |
| 897 |
} |
| 898 |
else { |
| 899 |
|
| 900 |
i++; |
| 901 |
} |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
if ( series.legCount() > 0 ) { |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
String originalSeriesStn2Name = seriesIn.getMappedStnName( series.getLegRaw(0).getToStn().getId() ); |
| 912 |
|
| 913 |
String originalSeriesName = seriesIn.getSeriesName() + "-" + originalSeriesStn2Name; |
| 914 |
int dotPos = originalSeriesStn2Name.lastIndexOf("."); |
| 915 |
if ( dotPos > 0 ) { |
| 916 |
|
| 917 |
originalSeriesName = originalSeriesStn2Name.substring(0, dotPos ); |
| 918 |
} |
| 919 |
series.setSeriesName( (outputSeries.innerSeriesCount() + 1) + "-" + originalSeriesName ); |
| 920 |
|
| 921 |
outputSeries.addSeries(series); |
| 922 |
} |
| 923 |
else { |
| 924 |
|
| 925 |
legsRemain = false; |
| 926 |
} |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
if ( seriesIn.legCount() > 0 ) { |
| 931 |
throw new RuntimeException( "Some legs could not be linked to other legs in the series." ); |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
logger.logMessage( "Linking series:" ); |
| 937 |
for ( int searchIdx = 0; searchIdx < outputSeries.innerSeriesCount(); searchIdx++ ) { |
| 938 |
SurveySeries seriesToLink = outputSeries.getInnerSeries(searchIdx); |
| 939 |
|
| 940 |
|
| 941 |
SurveyStation firstStn = seriesToLink.getLegRaw(0).getFromStn(); |
| 942 |
SurveyStation endStn = seriesToLink.getLegRaw( seriesToLink.legCount() - 1 ).getToStn(); |
| 943 |
|
| 944 |
|
| 945 |
int matchingIdx = findStationMatchingIdInInnerSeries(firstStn.getId(), searchIdx, outputSeries); |
| 946 |
if ( matchingIdx > -1 ){ |
| 947 |
logger.logMessage( "Series: " + outputSeries.getInnerSeries(searchIdx).getSeriesName() + |
| 948 |
" start stn linked to " + outputSeries.getInnerSeries(matchingIdx).getSeriesName() ); |
| 949 |
|
| 950 |
outputSeries.addLink(outputSeries.getInnerSeries(searchIdx).getSeriesName(), firstStn, |
| 951 |
outputSeries.getInnerSeries(matchingIdx).getSeriesName(), firstStn); |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
matchingIdx = findStationMatchingIdInInnerSeries(endStn.getId(), searchIdx, outputSeries); |
| 964 |
if ( matchingIdx > -1 ){ |
| 965 |
logger.logMessage( "Series: " + outputSeries.getInnerSeries(searchIdx).getSeriesName() + |
| 966 |
" end stn linked to " + outputSeries.getInnerSeries(matchingIdx).getSeriesName() ); |
| 967 |
|
| 968 |
|
| 969 |
outputSeries.addLink(outputSeries.getInnerSeries(searchIdx).getSeriesName(), endStn, |
| 970 |
outputSeries.getInnerSeries(matchingIdx).getSeriesName(), endStn); |
| 971 |
} |
| 972 |
|
| 973 |
} |
| 974 |
|
| 975 |
return outputSeries; |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
private static int findStationMatchingIdInInnerSeries(int id, int excludeSeriesIdx, SurveySeries series){ |
| 984 |
int matchingIdx = -1; |
| 985 |
|
| 986 |
ListIterator<SurveySeries> innerItr = series.getInnerSeriesList().listIterator(); |
| 987 |
int checkIdx = -1; |
| 988 |
while ( matchingIdx == -1 && innerItr.hasNext() ) { |
| 989 |
SurveySeries check = innerItr.next(); |
| 990 |
checkIdx++; |
| 991 |
|
| 992 |
if ( excludeSeriesIdx != checkIdx ) { |
| 993 |
|
| 994 |
for ( int legIdx = 0; legIdx < check.legCount(); legIdx++ ) { |
| 995 |
SurveyLeg leg = check.getLegRaw(legIdx); |
| 996 |
|
| 997 |
if ( id == leg.getFromStn().getId() ) { |
| 998 |
|
| 999 |
matchingIdx = checkIdx; |
| 1000 |
break; |
| 1001 |
} |
| 1002 |
else if ( id == leg.getToStn().getId() ) { |
| 1003 |
|
| 1004 |
matchingIdx = checkIdx; |
| 1005 |
break; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
return matchingIdx; |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
public static String[] cleanAndSplitDataLine( String dataIn ) { |
| 1022 |
|
| 1023 |
String dataLine = dataIn.replace('\t', ' ').trim(); |
| 1024 |
while ( dataLine.contains(" ") ) { |
| 1025 |
dataLine = dataLine.replaceAll(" ", " "); |
| 1026 |
} |
| 1027 |
return dataLine.split(" "); |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
public static String formatFileParserMsg( String message, int lineNo ) { |
| 1038 |
String msg = message; |
| 1039 |
|
| 1040 |
msg += " (Line: " + lineNo + ")"; |
| 1041 |
return msg; |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
public static String formatFileParserMsg( String message, String lineRef ) { |
| 1052 |
String msg = message; |
| 1053 |
|
| 1054 |
msg += " (Line ref: " + lineRef + ")"; |
| 1055 |
return msg; |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
public static String dataFormatLineForSeries( SurveySeries series, boolean legIsDiving ) { |
| 1066 |
List<String> dataOrder = series.getDataOrder(); |
| 1067 |
List<String> dataOrder2 = series.getDataOrder2(); |
| 1068 |
|
| 1069 |
|
| 1070 |
if ( dataOrder2.size() > 0 ) { |
| 1071 |
if ( dataOrderIsDiving( dataOrder ) != legIsDiving ) { |
| 1072 |
|
| 1073 |
dataOrder = dataOrder2; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
String dataOrderLine = ""; |
| 1078 |
boolean diving = false; |
| 1079 |
|
| 1080 |
|
| 1081 |
for (int i = 0; i < dataOrder.size(); i++) { |
| 1082 |
String item = dataOrder.get(i); |
| 1083 |
dataOrderLine += " " + item.toLowerCase(); |
| 1084 |
if ( item.contains("DEPTH") ) { |
| 1085 |
diving = true; |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 1089 |
if ( diving == true ) { |
| 1090 |
dataOrderLine = "diving" + dataOrderLine; |
| 1091 |
} |
| 1092 |
else { |
| 1093 |
dataOrderLine = "normal" + dataOrderLine; |
| 1094 |
} |
| 1095 |
|
| 1096 |
|
| 1097 |
if ( dataOrderLine.length() > 7 ) { |
| 1098 |
dataOrderLine = "data " + dataOrderLine; |
| 1099 |
} |
| 1100 |
else { |
| 1101 |
dataOrderLine = ""; |
| 1102 |
} |
| 1103 |
|
| 1104 |
return dataOrderLine; |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
public static boolean compareStringLists( List<String> list1, List<String> list2 ) { |
| 1114 |
boolean match = true; |
| 1115 |
|
| 1116 |
if ( list1.size() == list2.size() ) { |
| 1117 |
for ( int i = 0; i < list1.size(); i++ ) { |
| 1118 |
if ( list1.get(i).compareTo( list2.get(i) ) != 0 ) { |
| 1119 |
match = false; |
| 1120 |
break; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
} |
| 1124 |
else { |
| 1125 |
match = false; |
| 1126 |
} |
| 1127 |
|
| 1128 |
return match; |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
public static double lengthToMetres(double length, LengthUnit units) { |
| 1139 |
double metreLength = 0; |
| 1140 |
|
| 1141 |
switch (units) { |
| 1142 |
case Metres : |
| 1143 |
metreLength = length; |
| 1144 |
break; |
| 1145 |
case Feet : |
| 1146 |
metreLength = length / feetPerMetre; |
| 1147 |
break; |
| 1148 |
case Yards : |
| 1149 |
metreLength = length * 3 / feetPerMetre; |
| 1150 |
break; |
| 1151 |
default: |
| 1152 |
|
| 1153 |
break; |
| 1154 |
} |
| 1155 |
|
| 1156 |
return metreLength; |
| 1157 |
} |
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
public static double lengthFromMetres(double metrelength, LengthUnit units) { |
| 1167 |
double convertedLength = 0; |
| 1168 |
|
| 1169 |
switch (units) { |
| 1170 |
case Metres : |
| 1171 |
convertedLength = metrelength; |
| 1172 |
break; |
| 1173 |
case Feet : |
| 1174 |
convertedLength = metrelength * feetPerMetre; |
| 1175 |
break; |
| 1176 |
case Yards : |
| 1177 |
convertedLength = metrelength * feetPerMetre / 3; |
| 1178 |
break; |
| 1179 |
default: |
| 1180 |
|
| 1181 |
break; |
| 1182 |
} |
| 1183 |
|
| 1184 |
return convertedLength; |
| 1185 |
} |
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
public static double bearingToDegrees(double bearing, BearingUnit units) { |
| 1194 |
double degrees = -999; |
| 1195 |
|
| 1196 |
switch (units) { |
| 1197 |
case Degrees : |
| 1198 |
degrees = bearing; |
| 1199 |
break; |
| 1200 |
case Grads : |
| 1201 |
degrees = gradsToDegrees( bearing ); |
| 1202 |
break; |
| 1203 |
case Minutes : |
| 1204 |
degrees = bearing / 60; |
| 1205 |
break; |
| 1206 |
default: |
| 1207 |
|
| 1208 |
break; |
| 1209 |
} |
| 1210 |
|
| 1211 |
return degrees; |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
public static double bearingFromDegrees(double bearingDegrees, BearingUnit units) { |
| 1222 |
double convertedBearing = -999; |
| 1223 |
|
| 1224 |
switch (units) { |
| 1225 |
case Degrees : |
| 1226 |
convertedBearing = bearingDegrees; |
| 1227 |
break; |
| 1228 |
case Grads : |
| 1229 |
convertedBearing = degreesToGrads( bearingDegrees ); |
| 1230 |
break; |
| 1231 |
case Minutes : |
| 1232 |
convertedBearing = bearingDegrees * 60; |
| 1233 |
break; |
| 1234 |
default: |
| 1235 |
|
| 1236 |
break; |
| 1237 |
} |
| 1238 |
|
| 1239 |
return convertedBearing; |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
public static double gradientToDegrees(double gradient, GradientUnit units) { |
| 1249 |
double degrees = -999; |
| 1250 |
|
| 1251 |
switch (units) { |
| 1252 |
case Degrees : |
| 1253 |
degrees = bearingToDegrees( gradient, BearingUnit.Degrees ); |
| 1254 |
break; |
| 1255 |
case Grads : |
| 1256 |
degrees = bearingToDegrees( gradient, BearingUnit.Grads ); |
| 1257 |
break; |
| 1258 |
case Minutes : |
| 1259 |
degrees = bearingToDegrees( gradient, BearingUnit.Minutes ); |
| 1260 |
break; |
| 1261 |
case Percent : |
| 1262 |
degrees = 180 * ( Math.atan( gradient / 100 ) ) / Math.PI; |
| 1263 |
break; |
| 1264 |
default: |
| 1265 |
|
| 1266 |
break; |
| 1267 |
} |
| 1268 |
|
| 1269 |
return degrees; |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
public static double gradientFromDegrees(double gradientDegrees, GradientUnit units) { |
| 1280 |
double convertedGradient = -999; |
| 1281 |
|
| 1282 |
switch (units) { |
| 1283 |
case Degrees : |
| 1284 |
convertedGradient = bearingFromDegrees( gradientDegrees, BearingUnit.Degrees ); |
| 1285 |
break; |
| 1286 |
case Grads : |
| 1287 |
convertedGradient = bearingFromDegrees( gradientDegrees, BearingUnit.Grads ); |
| 1288 |
break; |
| 1289 |
case Minutes : |
| 1290 |
convertedGradient = bearingFromDegrees( gradientDegrees, BearingUnit.Minutes ); |
| 1291 |
break; |
| 1292 |
case Percent : |
| 1293 |
convertedGradient = 100.0 * Math.tan(Math.PI * gradientDegrees / 180.0); |
| 1294 |
break; |
| 1295 |
default: |
| 1296 |
|
| 1297 |
break; |
| 1298 |
} |
| 1299 |
|
| 1300 |
return convertedGradient; |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
public static boolean dataOrderIsDiving(List<String> checkDataOrder) { |
| 1309 |
boolean isDiving = false; |
| 1310 |
if ( checkDataOrder != null && |
| 1311 |
( checkDataOrder.contains("DEPTHCHANGE") || checkDataOrder.contains("FROMDEPTH") ) ) { |
| 1312 |
isDiving = true; |
| 1313 |
} |
| 1314 |
return isDiving; |
| 1315 |
|
| 1316 |
} |
| 1317 |
|
| 1318 |
private static double gradsToDegrees(double grads) { |
| 1319 |
double tmp = 360.0 * grads / 400.0; |
| 1320 |
return tmp; |
| 1321 |
} |
| 1322 |
|
| 1323 |
private static double degreesToGrads(double degrees) { |
| 1324 |
return 400.0 * degrees / 360.0; |
| 1325 |
} |
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
private static String folderFromFile( File file ) { |
| 1333 |
String path = file.getPath(); |
| 1334 |
String folderPath = "."; |
| 1335 |
String folderSep = File.separator; |
| 1336 |
|
| 1337 |
int splitPos = path.lastIndexOf( folderSep ); |
| 1338 |
if ( splitPos >= 0 ) { |
| 1339 |
folderPath = path.substring( 0, splitPos ); |
| 1340 |
} |
| 1341 |
|
| 1342 |
return folderPath; |
| 1343 |
} |
| 1344 |
|
| 1345 |
} |