Debian Codegraph @

src/footleg/cavesurvey/data/reader/PocketTopoParser.java

raw symbols SCIP
1 /**
2 * Copyright (C) 2009-2017 Paul Fretwell - aka 'Footleg' ([email protected])
3 *
4 * This file is part of Cave Converter.
5 *
6 * Cave Converter is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Cave Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Cave Converter. If not, see <http://www.gnu.org/licenses/>.
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.List;
25
26 import footleg.cavesurvey.converter.Logger;
27 import footleg.cavesurvey.converter.CaveConverter.BearingUnit;
28 import footleg.cavesurvey.converter.CaveConverter.GradientUnit;
29 import footleg.cavesurvey.converter.CaveConverter.LengthUnit;
30 import footleg.cavesurvey.data.model.CaveSurvey;
31 import footleg.cavesurvey.data.model.Equate;
32 import footleg.cavesurvey.data.model.SurveyLeg;
33 import footleg.cavesurvey.data.model.SurveySeries;
34 import footleg.cavesurvey.data.model.SurveyStation;
35 import footleg.cavesurvey.tools.UtilityFunctions;
36
37 /**
38 * Parser for PocketTopo Text export files.
39 *
40 * @author Footleg
41 * @version 2017.01.09 (ISO 8601 YYYY.MM.DD)
42 * @since 1.6 (The Java version used)
43 */
44 public class PocketTopoParser {
45 private Logger logger;
46
47 //Constants used to indicate what type of data is encoded on a data line in the file being parsed
48 private final int LINE_TYPE_LEG = 1;
49 private final int LINE_TYPE_SPLAY = 2;
50 private final int LINE_TYPE_EQUATE = 3;
51 private final int LINE_TYPE_COMMENT = 4;
52
53 /**
54 * Class constructor
55 * @param logger Logging class to output information, warning and error messages to
56 */
57 public PocketTopoParser( Logger logger ) {
58 super();
59 this.logger = logger;
60 }
61
62 /**
63 * Class to hold data parsed from a line in a PocketTopo exported text data file
64 */
65 private class TopoDataLine {
66 // start stepping through the array from the beginning
67 private String fromStn = "";
68 private String toStn = "";
69 private double tape = 0;
70 private double compass = 0;
71 private double clino = 0;
72 private String trip = "";
73 private String comment = "";
74 private int lineType = -1;
75
76 public String getFromStn() {
77 return fromStn;
78 }
79 public void setFromStn(String fromStn) {
80 this.fromStn = fromStn;
81 }
82 public String getToStn() {
83 return toStn;
84 }
85 public void setToStn(String toStn) {
86 this.toStn = toStn;
87 }
88 public double getTape() {
89 return tape;
90 }
91 public void setTape(double tape) {
92 this.tape = tape;
93 }
94 public double getCompass() {
95 return compass;
96 }
97 public void setCompass(double compass) {
98 this.compass = compass;
99 }
100 public double getClino() {
101 return clino;
102 }
103 public void setClino(double clino) {
104 this.clino = clino;
105 }
106 public String getTrip() {
107 return trip;
108 }
109 public void setTrip(String trip) {
110 this.trip = trip;
111 }
112 public String getComment() {
113 return comment;
114 }
115 public void setComment(String comment) {
116 this.comment = comment;
117 }
118 public int getLineType() {
119 return lineType;
120 }
121 public void setLineType(int lineType) {
122 this.lineType = lineType;
123 }
124 }
125
126 /**
127 * Parse PocketTopo exported text data file into the cave data model
128 *
129 * @param surveyFileData ListArray of data lines from a PocketTopo text file
130 * @return Cave Survey object
131 * @throws ParseException Exception raised when information in a survey data file is not supported or valid for the format
132 */
133 public CaveSurvey parseFile( List<String> surveyFileData ) throws ParseException {
134
135 //Create new list of survey series to hold data
136 CaveSurvey surveyData = new CaveSurvey(logger);
137 SurveySeries outerSeries = null;
138
139 String caveName = "";
140
141 //Create cache for trip settings (contains list of arrays each
142 //containing 3 strings for the id, date and magnetic declination)
143 List<String[]> trips = new ArrayList<String[]>();
144
145 //Create list for equates
146 List<Equate> equates = new ArrayList<Equate>();
147
148 //Initialise read state
149 int state = 0;
150
151 //Create arrays to cache shots while processing each leg
152 List<SurveyLeg> legShots = new ArrayList<SurveyLeg>();
153 List<SurveyLeg> splayShots = new ArrayList<SurveyLeg>();
154
155 //Cache vars for last leg processed
156 String lastShotStart = "";
157 int lastToStn = -1;
158 int lastSeriesNo = -1;
159 String lastTripCode = "";
160 boolean newLeg = false; //Gets set to true when a new leg is started
161 //Create vars for active series refs
162 SurveySeries series = null;
163 int activeSeries = -1;
164
165 //Loop through all data lines
166 for ( int lineIdx = 0; lineIdx <= surveyFileData.size(); lineIdx++ ) {
167 int lineNo = lineIdx + 1;
168
169 //Need to allow final pass through loop after all lines processed
170 String dataLine = null;
171 if ( lineIdx < surveyFileData.size() ) {
172 dataLine = surveyFileData.get(lineIdx);
173 }
174
175 //Skip blank lines but not null line as this indicates end of file
176 //and data cached from previous lines needs to be output
177 if ( ( dataLine == null ) || ( dataLine.length() > 0 ) ) {
178 //Process data
179 switch (state) {
180 case 0: //Header line
181 //My Cave (m, 360)
182 //Check for triple space separator with bracket
183 int pos = dataLine.indexOf(" (");
184 if ( pos > 0 ) {
185 String part1 = dataLine.substring(0, pos);
186 String part2 = dataLine.substring(pos + 3);
187 if ( part2.compareTo("(m, 360)") != 0 ) {
188 //Not a valid header
189 ParseException ex = new ParseException("Invalid file header. Unsupported units: " + part2, lineNo);
190 throw ex;
191 }
192 else {
193 //Take cave name from header, and create a new series for the cave
194 caveName = part1.replace(' ', '_');
195 outerSeries = new SurveySeries( caveName );
196 surveyData.add( outerSeries );
197 logger.logMessage("Cave name: " + caveName);
198 }
199 }
200
201 state = 1;
202 break;
203 case 1: //Trip settings in Header
204 if ( dataLine.substring(0, 1).compareTo("[") == 0 ){
205 //Trip settings
206 List<String> tripData = UtilityFunctions.parseDataStringIntoDataItems(dataLine);
207 //Copy into string array as rest of code uses a simple string array to store trip details
208 String[] trip = new String[tripData.size()];
209 if ( tripData.size() >= 3 ) {
210 if ( tripData.size() <= 4 ) {
211 //Write first 3 items into trip data record
212 for (int i = 0; i < tripData.size(); i++) {
213 trip[i] = tripData.get(i);
214 }
215 }
216 else {
217 //Invalid trip line (more than 4 items)
218 ParseException ex = new ParseException("Invalid file header. Trip data contain more than 4 items in line: " + dataLine, lineNo );
219 throw ex;
220 }
221 }
222 else {
223 //Invalid trip line (less than 3 items)
224 ParseException ex = new ParseException("Invalid file header. Trip data does not contain at least 3 items in line: " + dataLine, lineNo );
225 throw ex;
226 }
227 //Remove colon from trip code
228 if ( trip[0].charAt( trip[0].length() - 1 ) == ':' ) {
229 trip[0] = trip[0].substring( 0, trip[0].length() - 1 );
230 }
231 else {
232 //Invalid trip code
233 ParseException ex = new ParseException("Invalid file header. Unexpected trip code: " + trip[0] + " in line: " + dataLine, lineNo );
234 throw ex;
235 }
236 trips.add(trip);
237 logger.logMessage("Trip settings: " + trip[0] + " " + trip[1] + " " + trip[2]);
238 break;
239 }
240 else {
241 //Start of legs, so don't break, just update state
242 state = 2;
243 }
244 case 2: //Data lines
245 //Create temporary survey leg to parse the data line into
246 SurveyLeg shot = new SurveyLeg();
247 int seriesNo = -1;
248 String trip = "";
249 TopoDataLine data = null;
250 //Process data line if not at end of file
251 if ( dataLine != null ) {
252 // logger.logMessage("Data line " + CaveConverter.padNumber(lineNo, 4) + ": " + dataLine);
253 //Parse items into Topoline object
254 data = parseDataLine( UtilityFunctions.parseDataStringIntoDataItems( dataLine ) );
255 //Skip blank or all whitespace lines
256 if ( data.getLineType() > 0 ) {
257 //Add fields in common to all types of data line
258 int[] seriesStn = splitSeriesFromStn( data.getFromStn() );
259 seriesNo = seriesStn[0];
260 shot.setFromStn( new SurveyStation( seriesStn[1] ) );
261 shot.setLength( data.getTape(), LengthUnit.Metres );
262 shot.setCompass( data.getCompass(), BearingUnit.Degrees );
263 shot.setClino( data.getClino(), GradientUnit.Degrees );
264 shot.setComment( data.getComment() );
265 trip = data.getTrip();
266 if ( ( data.getLineType() == LINE_TYPE_LEG ) || ( data.getLineType() == LINE_TYPE_EQUATE ) ) {
267 //Survey Leg or equate also have a To Stn
268 int[] seriesStn2 = splitSeriesFromStn( data.getToStn() );
269 shot.setToStn( new SurveyStation( seriesStn2[1] ) );
270
271 //Check whether both stations are in same series
272 if ( seriesNo != seriesStn2[0] ) {
273 if ( data.getLineType() != LINE_TYPE_EQUATE ) {
274 //Leg changes series. Only allowed for equates.
275 ParseException ex = new ParseException("Legs linking different series must be zero length.", lineNo );
276 throw ex;
277 }
278 else {
279 //Series equate
280 Equate equate = new Equate( outerSeries.getSeriesName() + "." + seriesNo, shot.getFromStn().getName(),
281 outerSeries.getSeriesName() + "." + seriesStn2[0], shot.getToStn().getName() );
282 //Add to cache
283 equates.add(equate);
284 }
285 }
286 else if ( data.getLineType() == LINE_TYPE_EQUATE ) {
287 //Equate within series
288 Equate equate = new Equate( outerSeries.getSeriesName() + "." + seriesNo, shot.getFromStn().getName(),
289 outerSeries.getSeriesName() + "." + seriesStn2[0], shot.getToStn().getName() );
290 //Add to cache
291 equates.add(equate);
292 }
293
294 }
295 else {
296 //Splays do not have a to station, but the code relies on their being
297 //a dummy station, so create one with id = -1
298 shot.setToStn( new SurveyStation( -1 ) );
299 }
300 }
301 }
302 else {
303 //No more data, so just cached data to output from previous lines
304 //Initialise leg to dummy data so conditions below enable cached data to be processed
305 data = parseDataLine( UtilityFunctions.parseDataStringIntoDataItems( "DUMMY DUMMY 42.0 0.0 0.0 [1]" ) );
306 shot.setLength( data.getTape(), LengthUnit.Metres ); //Set dummy value so cached legs get processed
307 }
308 //Process shot if not an equate
309 if ( shot.getLength(LengthUnit.Metres) > 0 ) {
310 /**
311 * Check if this data is part of same leg already being processed.
312 * If the start station is different to the last one, or there is
313 * a to station which is different to the last to station then it
314 * is a new leg.
315 */
316 if ( lastShotStart.length() == 0 ) {
317 //First shot in file, so store start station
318 lastShotStart = data.getFromStn();
319 }
320 else if ( data.getFromStn().compareTo( lastShotStart ) != 0 ) {
321 //Start of new leg (start stn is different to last data line)
322 newLeg = true;
323 }
324 else if ( ( shot.getToStn().getId() != -1 )
325 && ( ( lastToStn != -1 ) )
326 && ( shot.getToStn().getId() != lastToStn ) ) {
327 //Start of new leg (end stn is different to to stn on last data line where last data line had a to stn)
328 newLeg = true;
329 }
330 else if ( ( lastToStn != -1 ) && ( shot.getToStn().getId() == -1 ) ) {
331 //New leg (no to stn on current data line, but last line had one)
332 newLeg = true;
333 }
334
335 if ( newLeg ) {
336 //Starting new leg, so process data for last one before
337 //storing this data
338
339 //Create new leg to store store processed data
340 SurveyLeg masterLeg = new SurveyLeg();
341
342 if ( legShots.size() > 0 ) {
343 //Set stations using first leg
344 masterLeg.setFromStn( legShots.get(0).getFromStn() );
345 masterLeg.setToStn( legShots.get(0).getToStn() );
346
347 //Calculate averages for leg shots
348 double tape = 0.0;
349 double clino = 0.0;
350 String comments = "";
351 //Use utility function to average bearings so values either side of north average correctly
352 double[] bearings = new double[legShots.size()];
353 for ( int i = 0; i < legShots.size(); i++ ) {
354 tape += legShots.get(i).getLength(LengthUnit.Metres);
355 bearings[i] = legShots.get(i).getCompass(BearingUnit.Degrees);
356 clino += legShots.get(i).getClino(GradientUnit.Degrees);
357 //Append comments from multiple shots into one comment
358 if ( legShots.get(i).getComment().length() > 0 ) {
359 if ( comments.length() > 0 ) {
360 comments += "; " + legShots.get(i).getComment();
361 }
362 else {
363 comments = legShots.get(i).getComment();
364 }
365 }
366
367 }
368
369 double aveCompass = UtilityFunctions.averageCompassBearings(bearings);
370 //Update master leg
371 masterLeg.setLength( tape / legShots.size(), LengthUnit.Metres );
372 masterLeg.setCompass( aveCompass, BearingUnit.Degrees );
373 masterLeg.setClino( clino / legShots.size(), GradientUnit.Degrees );
374 masterLeg.setComment( comments );
375 }
376
377 //Determine if this leg belongs to the active series
378 if ( activeSeries != lastSeriesNo ) {
379 //Different series, see if this series already exists
380 boolean gotSeries = false;
381 for ( int j = 0; j < outerSeries.innerSeriesCount(); j++ ) {
382 //Check for matching series
383 if ( outerSeries.getInnerSeries(j).getSeriesName().compareTo( "" + lastSeriesNo ) == 0 ) {
384 //Found match, so get reference to this one
385 series = outerSeries.getInnerSeries(j);
386 gotSeries = true;
387 //Exit loop
388 j = outerSeries.innerSeriesCount();
389 }
390 }
391
392 if ( gotSeries == false ) {
393 //No series found, so need to create one
394 series = new SurveySeries( "" + lastSeriesNo );
395 //Find compass calibration for this new series
396 for ( int j = 0; j < trips.size(); j++ ) {
397 if ( lastTripCode.compareTo( trips.get(j)[0] ) == 0 ) {
398 //Use calibration for this trip
399 series.setDeclination( Double.valueOf( trips.get(j)[2] ) );
400 //Set date for trip (will be string of format yyyy/mm/dd)
401 String tripDateString = trips.get(j)[1];
402 Date tripDate = UtilityFunctions.stringToDate(tripDateString, "yyyy/MM/dd");
403 series.setSurveyDate( tripDate );
404 //Add comment to series if a trip comment exists
405 if ( trips.get(j).length == 4 ) {
406 series.setComment(trips.get(j)[3]);
407 }
408 }
409 }
410 //Add new series to list
411 outerSeries.addSeries( series );
412 }
413 //Set active series number to match new active series
414 activeSeries = lastSeriesNo;
415 }
416
417 //Process Splays for this leg
418 int stnSplayCount = 0;
419 String lastSplayFromStn = "";
420 for ( int i = 0; i < splayShots.size(); i++ ) {
421 //Need to increment splay count for number of splays already added to series from this station
422 //unless we already know this due to last splay being from the same station
423 if ( ( i == 0 ) || ( lastSplayFromStn.equals( splayShots.get(i).getFromStn().getName() ) == false ) ) {
424 //Count previous splays matching this fromStn in series
425 stnSplayCount = 0;
426 for ( int legIdx = 0; legIdx < series.legCount(); legIdx++ ) {
427 SurveyLeg chkLeg = series.getLegRaw( legIdx );
428 if ( ( chkLeg.isSplay() )
429 && ( chkLeg.getFromStn().getName().equals( splayShots.get(i).getFromStn().getName() ) ) ) {
430 stnSplayCount++;
431 }
432 }
433 }
434 //Add shot as a splay
435 stnSplayCount++;
436 addSplayShot(series, splayShots.get(i), stnSplayCount);
437 }
438
439 //Add master leg to series unless a dummy leg (will have negative length)
440 if ( masterLeg.getLength(LengthUnit.Metres) >= 0 ) {
441 series.addLeg( masterLeg );
442 }
443
444 //Clear caches
445 legShots = new ArrayList<SurveyLeg>();
446 splayShots = new ArrayList<SurveyLeg>();
447
448 //Update stn names for this new leg
449 lastShotStart = data.getFromStn();
450
451 //Reset flags
452 newLeg = false;
453 }
454
455 //Process current leg unless a dummy end of file line
456 if ( dataLine != null ) {
457 //Determine whether a splay shot or a leg shot
458 if ( shot.getToStn().getId() == -1 ) {
459 //Passage dimension shot
460 splayShots.add(shot);
461 }
462 else {
463 //Survey Leg, add to list
464 legShots.add(shot);
465 }
466
467 //Cache series no for this leg to be used next loop
468 lastSeriesNo = seriesNo;
469 lastTripCode = trip;
470
471 //Store to stn for comparison on next pass
472 lastToStn = shot.getToStn().getId();
473 }
474 }
475
476 break;
477 default:
478 }
479 }
480 }
481
482 //Process equates
483 UtilityFunctions.processEquates(equates, surveyData);
484
485 //Debug dump
486 UtilityFunctions.logSurveyDebugData(surveyData, logger);
487
488 //Completed file parsing
489 // logger.logMessage("Processed " + legCount + " survey legs in " +
490 // surveyData.size() + " series.");
491 return surveyData;
492 }
493
494 /**
495 * Splits a series.station name string into the component integers
496 *
497 * @param dataIn String consisting of a numeric series name and numeric station name separated with a dot
498 * @return An array of two integers, the series number and the station number
499 */
500 private int[] splitSeriesFromStn( String dataIn ) {
501 //Split a series.station into the component integers
502 int[] result = new int[2];
503
504 int pos = dataIn.indexOf('.');
505 if ( pos > 0 ) {
506 result[0] = Integer.valueOf( dataIn.substring( 0, pos ) );
507 result[1] = Integer.valueOf( dataIn.substring( pos + 1 ) );
508 }
509 else {
510 //Invalid series+station name
511 RuntimeException ex = new RuntimeException("Invalid dot separated series and station name : " + dataIn);
512 throw ex;
513 }
514
515 return result;
516 }
517
518 /**
519 * Determines what type of data a line of the file is representing
520 */
521 private TopoDataLine parseDataLine( List<String> dataItems ) {
522 //Equate lines do not always have trip numbers ( [1] )
523 //Lines may be and equate with an optional trip and optional comment
524 //e.g. 1.0 1.1 0.000 0.00 0.00
525 //e.g. 1.10 3.0 0.000 0.00 0.00 [1]
526 //e.g. 1.0 1.1 0.000 0.00 0.00 "Equate with a comment."
527 //e.g. 1.10 3.0 0.000 0.00 0.00 [1] "Equate with a comment."
528
529 //Lines can define a station with no other data, or just a comment
530 //e.g. 1.0 0.00 0.00 0.00
531 //e.g. 1.0 0.000 0.00 0.00 "Just a comment."
532
533 //Lines can represent legs, with or without comments
534 //e.g. 1.1 1.2 2.050 260.84 -56.40 [1]
535 //e.g. 1.0 1.2 5.234 3.18 -5.07 [1] "1.2=rawl plug on rear wall of blockhouse "
536
537 //Lines can represent splay shots, with or without comments
538 //e.g. 1.1 0.670 344.92 4.15 [1]
539 //e.g. 1.1 0.670 344.92 4.15 [1] "Splay with a comment."
540
541 TopoDataLine result = new TopoDataLine();
542
543 //Check line is valid (has at least 4 items)
544 if ( dataItems.size() > 4 ) {
545 //There will be either 4 or 5 data items in any line, followed by optional trip and comment items
546 int tripIdx = -1;
547 int commentIdx = -1;
548
549 String lastItem = dataItems.get( dataItems.size() - 1 );
550 String lastButOneItem = dataItems.get( dataItems.size() - 2 );
551
552 //Check if last item is a trip
553 if ( itemIsTrip( lastItem ) ) {
554 //Last item is trip
555 tripIdx = dataItems.size() - 1;
556 }
557 else if ( itemIsTrip( lastButOneItem ) ) {
558 //Last item is trip
559 tripIdx = dataItems.size() - 2;
560 //Last item in line has to be a comment
561 commentIdx = dataItems.size() - 1;
562 }
563 else {
564 //No trip, but is last item a comment?
565 if ( dataItems.size() > 5 ) {
566 //Last item in line has to be a comment
567 commentIdx = dataItems.size() - 1;
568 }
569 else if ( dataItems.size() == 5 ) {
570 //Last item in line is either a comment or a zero value
571 if ( itemIsZeroValue( lastItem ) == false ) {
572 //Last item in line has to be a comment
573 commentIdx = dataItems.size() - 1;
574 }
575 }
576 }
577
578 //All items have a from station
579 result.setFromStn( dataItems.get(0) );
580
581 if ( ( tripIdx == 4 ) || ( commentIdx == 4 ) ) {
582 //If trip or comment idx=4 then line is a splay leg
583 result.setTape( Double.valueOf( dataItems.get(1) ) );
584 result.setCompass( Double.valueOf( dataItems.get(2) ) );
585 result.setClino( Double.valueOf( dataItems.get(3) ) );
586 //Check whether line is really a splay, null data, or just a comment
587 if ( ( result.getTape() == 0.0 )
588 && ( result.getCompass() == 0.0 )
589 && ( result.getClino() == 0.0 ) ) {
590 if ( commentIdx > 0 ) {
591 result.setLineType( LINE_TYPE_COMMENT );
592 }
593 else {
594 //No data on line apart from from stn. Null line.
595 result.setLineType( 0 );
596 }
597 }
598 else {
599 result.setLineType( LINE_TYPE_SPLAY );
600 }
601 }
602 else if ( ( tripIdx == 5 ) || ( commentIdx == 5 ) || ( ( tripIdx == -1 ) && ( commentIdx == -1 ) ) ) {
603 //If trip or comment idx=5, or there is neither a trip or comment then line is a survey leg
604 result.setToStn( dataItems.get(1) );
605 result.setTape( Double.valueOf( dataItems.get(2) ) );
606 result.setCompass( Double.valueOf( dataItems.get(3) ) );
607 result.setClino( Double.valueOf( dataItems.get(4) ) );
608 //Check whether line is an equate or a leg
609 if ( ( result.getTape() == 0.0 )
610 && ( result.getCompass() == 0.0 )
611 && ( result.getClino() == 0.0 ) ) {
612 result.setLineType( LINE_TYPE_EQUATE );
613 }
614 else {
615 result.setLineType( LINE_TYPE_LEG );
616 }
617 }
618
619 //Add trip and comment if present
620 if ( tripIdx > 0 ) {
621 result.setTrip( dataItems.get( tripIdx ) );
622 }
623 if ( commentIdx > 0 ) {
624 result.setComment( dataItems.get( commentIdx ) );
625 }
626
627 }
628
629 return result;
630 }
631
632 private boolean itemIsTrip( String dataItem ) {
633 boolean isTrip = false;
634 if ( ( dataItem.length() > 2 ) && ( dataItem.length() < 4 )
635 && ( dataItem.charAt( 0 ) == '[' ) && ( dataItem.charAt( dataItem.length() - 1 ) == ']' ) ) {
636 //Found trip item
637 isTrip = true;
638 }
639 return isTrip;
640 }
641
642 private boolean itemIsZeroValue( String dataItem ) {
643 boolean isZero = false;
644
645 //Check items starts with '0.0'
646 if ( dataItem.length() > 2 ) {
647 if ( ( dataItem.charAt(0) == '0' ) && ( dataItem.charAt(1) == '.' ) && ( dataItem.charAt(2) == '0' ) ) {
648 //Potentially a zero value string
649 isZero = true;
650 //Loop through remaining characters checking they are all zeros
651 for (int i = 3; i < dataItem.length(); i++) {
652 if ( dataItem.charAt(i) != '0' ) {
653 //Item is not a zero value
654 isZero = false;
655 i = dataItem.length();
656 }
657 }
658 }
659 }
660 else {
661 //Allow '0' and '00'
662 //Potentially a zero value string
663 isZero = true;
664 //Loop through remaining characters checking they are all zeros
665 for (int i = 0; i < dataItem.length(); i++) {
666 if ( dataItem.charAt(i) != '0' ) {
667 //Item is not a zero value
668 isZero = false;
669 i = dataItem.length();
670 }
671 }
672 }
673
674 return isZero;
675 }
676
677 /*
678 * processSplaysArray
679 *
680 * Processes an array of splay shots. Will return an LRUD dimension or
681 private double processSplaysArray( SurveyLeg splays[], int bestIdx, SurveySeries series ) {
682 for ( int i = 0; i < upShots.size(); i++ ) {
683 if ( i == bestIdx ) {
684 //Found best up shot
685 masterLeg.setUp( upShots.get(i).getLength() );
686 }
687 else {
688 //Other shots, add as splay
689 SurveyLeg splayShot = new SurveyLeg();
690 splayShot.setFromStn( upShots.get(i).getFromStn() );
691 String toStn = upShots.get(i).getFromStn() + new Character( (char)stnLetterCode++ ).toString();
692 splayShot.setToStn( CaveConverter.stnNameToNumber( toStn, series ) );
693 splayShot.setLength( upShots.get(i).getLength() );
694 splayShot.setCompass( upShots.get(i).getCompass() );
695 splayShot.setClino( upShots.get(i).getClino() );
696 splayShot.setSplay( true );
697 series.addLeg( splayShot );
698 legCount++;
699 }
700 }
701 }
702 */
703
704 private void addSplayShot( SurveySeries series, SurveyLeg shot, int splayCount ){
705 //Generate station name suffix for splay (97 = letter 'a')
706 int increment = splayCount - 1; //Zero based
707 int stnLetterCode = 97; //97 = letter 'a'
708 String stnSuffix = "";
709 if ( splayCount < 27 ) {
710 stnSuffix = new Character( (char)(stnLetterCode + increment) ).toString();
711 }
712 else {
713 int primaryCount = (increment - 26) / 26;
714 int secondaryCount = (increment % 26);
715 stnSuffix = new Character( (char)(stnLetterCode + primaryCount) ).toString();
716 stnSuffix += new Character( (char)(stnLetterCode + secondaryCount) ).toString();
717 }
718
719 //Add shot as a splay
720 //TODO Stns names should be screened against legal character list, wherever it is that they are set
721 SurveyLeg splayShot = shot.clone();
722 String toStn = shot.getFromStn().getName() + stnSuffix;
723 splayShot.setToStn( UtilityFunctions.createStationFromNameForSeries( toStn, series ) );
724 splayShot.setLength( shot.getLength(LengthUnit.Metres), LengthUnit.Metres );
725 splayShot.setCompass( shot.getCompass(BearingUnit.Degrees), BearingUnit.Degrees );
726 splayShot.setClino( shot.getClino(GradientUnit.Degrees), GradientUnit.Degrees );
727 splayShot.setSplay( true );
728 series.addLeg( splayShot );
729 }
730
731 }