@speleotica/frcsdata 3.0.1 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/FrcsPlotFile.js +5 -1
  2. package/FrcsPlotShot.js +5 -1
  3. package/FrcsShot.d.ts +25 -4
  4. package/FrcsShot.js +4 -5
  5. package/FrcsSurveyFile.js +5 -1
  6. package/FrcsTrip.js +5 -1
  7. package/FrcsTripSummary.js +5 -1
  8. package/FrcsTripSummaryFile.js +5 -1
  9. package/es/FrcsPlotFile.js +5 -1
  10. package/es/FrcsPlotShot.js +5 -1
  11. package/es/FrcsShot.js +5 -6
  12. package/es/FrcsSurveyFile.js +5 -1
  13. package/es/FrcsTrip.js +5 -1
  14. package/es/FrcsTripSummary.js +5 -1
  15. package/es/FrcsTripSummaryFile.js +5 -1
  16. package/es/formatFrcsShot.js +75 -0
  17. package/es/formatFrcsShot.spec.js +141 -0
  18. package/es/index.js +24 -28
  19. package/es/node/index.js +2 -10
  20. package/es/node/parseFrcsPlotFile.spec.js +1 -5
  21. package/es/node/parseFrcsSurveyFile.spec.js +115 -69
  22. package/es/node/parseFrcsTripSummaryFile.spec.js +1 -5
  23. package/es/parseFrcsPlotFile.js +1 -26
  24. package/es/parseFrcsSurveyFile.js +75 -103
  25. package/es/parseFrcsTripSummaryFile.js +1 -12
  26. package/es/string/index.js +2 -9
  27. package/es/string/parseFrcsPlotFile.spec.js +1 -5
  28. package/es/string/parseFrcsSurveyFile.spec.js +205 -109
  29. package/formatFrcsShot.d.ts +3 -0
  30. package/formatFrcsShot.js +72 -0
  31. package/formatFrcsShot.spec.js +139 -0
  32. package/index.d.ts +2 -1
  33. package/index.js +24 -28
  34. package/node/index.js +1 -9
  35. package/node/parseFrcsPlotFile.spec.js +165 -180
  36. package/node/parseFrcsSurveyFile.spec.js +270 -235
  37. package/node/parseFrcsTripSummaryFile.spec.js +83 -106
  38. package/package.json +15 -15
  39. package/parseFrcsPlotFile.js +224 -318
  40. package/parseFrcsSurveyFile.js +422 -431
  41. package/parseFrcsTripSummaryFile.js +102 -142
  42. package/string/index.js +10 -27
  43. package/string/parseFrcsPlotFile.spec.js +165 -180
  44. package/string/parseFrcsSurveyFile.spec.js +545 -541
  45. package/yarn.lock +1285 -702
@@ -1,117 +1,95 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = parseFrcsSurveyFile;
9
-
10
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
15
-
16
11
  var _parseSegment = require("parse-segment");
17
-
18
12
  var _unitized = require("@speleotica/unitized");
19
-
20
13
  var _FrcsShot = require("./FrcsShot");
21
-
14
+ function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
15
+ function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, "return": function _return(value) { var ret = this.s["return"]; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, "throw": function _throw(value) { var thr = this.s["return"]; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); }
22
16
  function parseNumber(s, unit) {
23
17
  var value = parseFloat(s);
24
18
  if (isNaN(value)) return null;
25
19
  return new _unitized.UnitizedNumber(value, unit);
26
20
  }
27
-
28
21
  function parseAzimuth(s, unit) {
29
22
  var parsed = parseNumber(s, unit);
30
23
  return (parsed === null || parsed === void 0 ? void 0 : parsed.get(_unitized.Angle.degrees)) === 360 ? _unitized.Unitize.degrees(0) : parsed;
31
24
  }
32
-
33
25
  function parseKind(kind) {
34
26
  switch (kind) {
35
27
  case 'H':
36
28
  return _FrcsShot.FrcsShotKind.Horizontal;
37
-
38
29
  case 'D':
39
30
  return _FrcsShot.FrcsShotKind.Diagonal;
40
-
41
31
  default:
42
32
  return _FrcsShot.FrcsShotKind.Normal;
43
33
  }
44
34
  }
45
-
46
35
  function parseLengthUnit(unit) {
47
36
  switch (unit) {
48
37
  case 'FI':
49
38
  return _unitized.Length.inches;
50
-
39
+ case 'FF':
51
40
  case 'FT':
52
41
  return _unitized.Length.feet;
53
-
42
+ case 'MT':
54
43
  case 'M ':
55
44
  return _unitized.Length.meters;
56
45
  }
57
-
58
46
  return null;
59
47
  }
60
-
61
48
  function parseAngleUnit(unit) {
62
49
  switch (unit) {
63
50
  case 'D':
64
51
  return _unitized.Angle.degrees;
65
-
66
52
  case 'G':
67
53
  return _unitized.Angle.gradians;
68
-
69
54
  case 'M':
70
55
  return _unitized.Angle.milsNATO;
71
56
  }
72
-
73
57
  return null;
74
- } // determines if a cell contains a valid station name.
75
-
58
+ }
76
59
 
60
+ // determines if a cell contains a valid station name.
77
61
  function isValidStation(s) {
78
62
  return /^\s*\S+\s*$/.test(s);
79
- } // determines if a cell contains a valid unsigned integer.
80
-
81
-
63
+ }
64
+ // determines if a cell contains a valid unsigned integer.
82
65
  function isValidUInt(s) {
83
66
  return /^\s*[0-9]+\s*$/.test(s);
84
- } // determines if a cell contains a valid float.
85
-
86
-
67
+ }
68
+ // determines if a cell contains a valid float.
87
69
  function isValidFloat(s) {
88
70
  return /^\s*[-+]?([0-9]+(\.[0-9]*)?|\.[0-9]+)\s*$/.test(s);
89
- } // determines if a cell contains a valid unsigned float or whitespace.
90
-
91
-
71
+ }
72
+ // determines if a cell contains a valid unsigned float or whitespace.
92
73
  function isValidOptFloat(s) {
93
74
  return /^\s*[-+]?[0-9]*(\.[0-9]*)?\s*$/.test(s);
94
- } // determines if a cell contains a valid unsigned float or whitespace.
95
-
96
-
75
+ }
76
+ // determines if a cell contains a valid unsigned float or whitespace.
97
77
  function isValidOptUFloat(s) {
98
78
  return /^\s*[0-9]*(\.[0-9]*)?\s*$/.test(s);
99
- } // determines if a cell contains a valid unsigned float.
100
-
101
-
79
+ }
80
+ // determines if a cell contains a valid unsigned float.
102
81
  function isValidUFloat(s) {
103
82
  return /^\s*([0-9]+(\.[0-9]*)?|\.[0-9]+)\s*$/.test(s);
104
- } // determines if a cell contains a valid inclination or whitespace.
105
-
106
-
83
+ }
84
+ // determines if a cell contains a valid inclination or whitespace.
107
85
  function isValidOptInclination(s) {
108
86
  return /^\s*[-+]?[0-9]*(\.[0-9]*)?\s*$/.test(s);
109
87
  }
110
-
111
88
  function parseLrud(s, unit) {
112
89
  var value = parseFloat(s);
113
90
  return !Number.isFinite(value) || value < 0 ? null : new _unitized.UnitizedNumber(value, unit);
114
91
  }
92
+
115
93
  /**
116
94
  * Parses a raw cdata.fr survey file. These look like so:
117
95
  *
@@ -157,214 +135,229 @@ FI B DD
157
135
  ...</pre>
158
136
  *
159
137
  */
160
-
161
-
162
138
  function parseFrcsSurveyFile(_x, _x2) {
163
139
  return _parseFrcsSurveyFile.apply(this, arguments);
164
140
  }
165
-
166
141
  function _parseFrcsSurveyFile() {
167
- _parseFrcsSurveyFile = (0, _asyncToGenerator2["default"])(
168
- /*#__PURE__*/
169
- _regenerator["default"].mark(function _callee(file, // eslint-disable-line @typescript-eslint/no-explicit-any
142
+ _parseFrcsSurveyFile = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(file,
143
+ // eslint-disable-line @typescript-eslint/no-explicit-any
170
144
  lines) {
171
- var cave, location, trips, errors, tripName, tripTeam, tripDate, inTripComment, tripCommentStartLine, tripCommentEndLine, tripComment, commentLines, trip, inBlockComment, section, getComment, lineNumber, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, _value, _ret;
172
-
173
- return _regenerator["default"].wrap(function _callee$(_context) {
174
- while (1) {
175
- switch (_context.prev = _context.next) {
176
- case 0:
177
- getComment = function _ref() {
178
- if (!commentLines) return null;
179
- var comment = commentLines.join('\n').trim();
180
- commentLines = null;
181
- return comment || null;
182
- };
183
-
184
- cave = null;
185
- location = null;
186
- trips = [];
187
- errors = [];
188
- inTripComment = true;
189
- tripCommentStartLine = 1;
190
- tripCommentEndLine = -1;
191
- tripComment = [];
145
+ var cave, location, trips, errors, tripName, tripTeam, tripDate, inTripComment, tripCommentStartLine, tripCommentEndLine, tripComment, commentLines, trip, inBlockComment, section, getComment, lineNumber, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, _ret;
146
+ return _regenerator["default"].wrap(function _callee$(_context2) {
147
+ while (1) switch (_context2.prev = _context2.next) {
148
+ case 0:
149
+ getComment = function _getComment() {
150
+ if (!commentLines) return null;
151
+ var comment = commentLines.join('\n').trim();
192
152
  commentLines = null;
193
- trip = null;
194
- inBlockComment = false;
195
- lineNumber = 0;
196
- _iteratorNormalCompletion = true;
197
- _didIteratorError = false;
198
- _context.prev = 15;
199
-
200
- _loop = function _loop() {
201
- var line = _value;
202
- var errored = false;
203
- var thisLineNumber = lineNumber;
204
-
205
- var error = function error(message, startColumn, endColumn) {
206
- errored = true;
207
- errors.push(new _parseSegment.SegmentParseError(message, new _parseSegment.Segment({
208
- value: line,
209
- source: file,
210
- startLine: thisLineNumber,
211
- startCol: 0
212
- }).substring(startColumn, endColumn)));
213
- };
214
-
215
- var validate = function validate(startColumn, endColumn, fieldName, validator) {
216
- var field = line.substring(startColumn, endColumn);
217
-
218
- if (!validator(field)) {
219
- error((field.trim() ? 'Invalid ' : 'Missing ') + fieldName, startColumn, endColumn);
220
- }
221
-
222
- return field;
223
- };
224
-
225
- lineNumber++;
226
-
227
- if (lineNumber === 1) {
228
- var match = /^\s*([^,]+)(,(.*))?/.exec(line);
229
-
230
- if (match) {
231
- cave = match[1].trim();
232
-
233
- if (match[3]) {
234
- location = match[3].trim();
153
+ return comment || null;
154
+ };
155
+ cave = null;
156
+ location = null;
157
+ trips = [];
158
+ errors = [];
159
+ inTripComment = true;
160
+ tripCommentStartLine = 1;
161
+ tripCommentEndLine = -1;
162
+ tripComment = [];
163
+ commentLines = null;
164
+ trip = null;
165
+ inBlockComment = false;
166
+ lineNumber = 0;
167
+ _iteratorAbruptCompletion = false;
168
+ _didIteratorError = false;
169
+ _context2.prev = 15;
170
+ _loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
171
+ var line, errored, thisLineNumber, error, validate, match, _match, k, team, month, day, year, _match2, part, distanceUnit, azimuthUnit, inclinationUnit, backsightAzimuthCorrected, backsightInclinationCorrected, hasBacksightAzimuth, hasBacksightInclination, _trip, shots, _trip$header, _azimuthUnit, _inclinationUnit, _distanceUnit, inches, fromStr, lStr, rStr, uStr, dStr, up, down, left, right, toStr, _shot, fromLrudMatch, fromLruds, _fromLrudMatch$1$trim, _fromLrudMatch$1$trim2, _left, _right, _up, _down, azmFsStr, azmBsStr, incFsStr, incBsStr, kind, distance, horizontalDistance, verticalDistance, frontsightInclination, backsightInclination, excludeDistance, isSplay, feetStr, inchesStr, invalid, _feetStr, h, v, d, _v, frontsightAzimuth, backsightAzimuth, shot;
172
+ return _regenerator["default"].wrap(function _loop$(_context) {
173
+ while (1) switch (_context.prev = _context.next) {
174
+ case 0:
175
+ line = _step.value;
176
+ errored = false;
177
+ thisLineNumber = lineNumber;
178
+ error = function error(message, startColumn, endColumn) {
179
+ errored = true;
180
+ errors.push(new _parseSegment.SegmentParseError(message, new _parseSegment.Segment({
181
+ value: line,
182
+ source: file,
183
+ startLine: thisLineNumber,
184
+ startCol: 0
185
+ }).substring(startColumn, endColumn)));
186
+ };
187
+ validate = function validate(startColumn, endColumn, fieldName, validator) {
188
+ var field = line.substring(startColumn, endColumn);
189
+ if (!validator(field)) {
190
+ error((field.trim() ? 'Invalid ' : 'Missing ') + fieldName, startColumn, endColumn);
191
+ }
192
+ return field;
193
+ };
194
+ lineNumber++;
195
+ if (lineNumber === 1) {
196
+ match = /^\s*([^,]+)(,(.*))?/.exec(line);
197
+ if (match) {
198
+ cave = match[1].trim();
199
+ if (match[3]) {
200
+ location = match[3].trim();
201
+ }
202
+ }
235
203
  }
236
- }
237
- }
238
-
239
- if (line.charAt(0) === ' ' && line.charAt(1) === '*') {
240
- inTripComment = !inTripComment;
241
-
242
- if (inTripComment) {
243
- section = undefined;
244
- tripComment = [];
245
- tripCommentStartLine = lineNumber;
246
- } else {
247
- tripCommentEndLine = lineNumber;
248
- }
249
- } else if (inTripComment) {
250
- if (lineNumber === tripCommentStartLine + 1) {
251
- tripName = line && line.trim();
252
- } else if (lineNumber === tripCommentStartLine + 2) {
253
- var _match2 = /^(.+?)\s*[-.]\s*(\d+)\/(\d+)\/(\d+)$/.exec(line && line.trim());
254
-
204
+ if (!(line.charAt(0) === ' ' && line.charAt(1) === '*')) {
205
+ _context.next = 12;
206
+ break;
207
+ }
208
+ inTripComment = !inTripComment;
209
+ if (inTripComment) {
210
+ section = undefined;
211
+ tripComment = [];
212
+ tripCommentStartLine = lineNumber;
213
+ } else {
214
+ tripCommentEndLine = lineNumber;
215
+ }
216
+ _context.next = 107;
217
+ break;
218
+ case 12:
219
+ if (!inTripComment) {
220
+ _context.next = 18;
221
+ break;
222
+ }
223
+ if (lineNumber === tripCommentStartLine + 1) {
224
+ tripName = line && line.trim();
225
+ } else if (lineNumber === tripCommentStartLine + 2) {
226
+ _match = /^(.+?)\s*[-.]\s*(\d+)\/(\d+)\/(\d+)$/.exec(line && line.trim());
227
+ if (_match) {
228
+ k = 1;
229
+ team = _match[k++];
230
+ month = parseInt(_match[k++]);
231
+ day = parseInt(_match[k++]);
232
+ year = parseInt(_match[k++]);
233
+ tripDate = new Date(year < 70 ? year + 2000 : year, month - 1, day);
234
+ tripTeam = team.split(team.indexOf(';') >= 0 ? /\s*;\s*/g : /\s*,\s*/g);
235
+ }
236
+ } else if (lineNumber > 1) {
237
+ tripComment.push(line);
238
+ }
239
+ _match2 = /^\*\*\*([^*])\*\*\*/.exec(line);
255
240
  if (_match2) {
256
- var k = 1;
257
- var team = _match2[k++];
258
- var month = parseInt(_match2[k++]);
259
- var day = parseInt(_match2[k++]);
260
- var year = parseInt(_match2[k++]);
261
- tripDate = new Date(year < 70 ? year + 2000 : year, month - 1, day);
262
- tripTeam = team.split(team.indexOf(';') >= 0 ? /\s*;\s*/g : /\s*,\s*/g);
241
+ section = _match2[1].trim();
263
242
  }
264
- } else if (lineNumber > 1) {
265
- tripComment.push(line);
266
- }
267
-
268
- var _match = /^\*\*\*([^*])\*\*\*/.exec(line);
269
-
270
- if (_match) {
271
- section = _match[1].trim();
272
- }
273
- } else if (line.charAt(0) === '*') {
274
- inBlockComment = !inBlockComment;
275
- if (inBlockComment) commentLines = [];else if (commentLines) {
276
- var part = line.substring(1).trim();
277
- if (part && commentLines) commentLines.push(part);
278
- }
279
- } else if (inBlockComment) {
280
- if (commentLines) commentLines.push(line);
281
- } else if (lineNumber === tripCommentEndLine + 1) {
282
- // FT CC DD
283
- // 01234567
284
- var distanceUnit = parseLengthUnit(line.slice(0, 2));
285
-
286
- if (!distanceUnit) {
287
- distanceUnit = _unitized.Length.feet;
288
- error('Invalid distance unit', 0, 2);
289
- }
290
-
291
- var azimuthUnit = parseAngleUnit(line[6]);
292
-
293
- if (!azimuthUnit) {
294
- azimuthUnit = _unitized.Angle.degrees;
295
- error('Invalid azimuth unit', 6, 7);
296
- }
297
-
298
- var inclinationUnit = parseAngleUnit(line[7]);
299
-
300
- if (!inclinationUnit) {
301
- inclinationUnit = _unitized.Angle.degrees;
302
- error('Invalid inclination unit', 7, 8);
303
- }
304
-
305
- var backsightAzimuthCorrected = line[3] === 'C';
306
- var backsightInclinationCorrected = line[4] === 'C';
307
- var hasBacksightAzimuth = line[3] !== ' ' && line[3] !== '-';
308
- var hasBacksightInclination = line[4] !== ' ' && line[4] !== '-';
309
-
310
- if (!/[-CB ]/.test(line[3])) {
311
- error('Invalid backsight azimuth type', 3, 4);
312
- }
313
-
314
- if (!/[-CB ]/.test(line[4])) {
315
- error('Invalid backsight inclination type', 4, 5);
316
- }
317
-
318
- trip = {
319
- header: {
320
- name: tripName || '',
321
- comment: tripComment && tripComment.join('\n') || null,
322
- section: section,
323
- date: tripDate,
324
- team: tripTeam,
325
- distanceUnit: distanceUnit,
326
- azimuthUnit: azimuthUnit,
327
- inclinationUnit: inclinationUnit,
328
- backsightAzimuthCorrected: backsightAzimuthCorrected,
329
- backsightInclinationCorrected: backsightInclinationCorrected,
330
- hasBacksightAzimuth: hasBacksightAzimuth,
331
- hasBacksightInclination: hasBacksightInclination
332
- },
333
- shots: []
334
- };
335
- trips.push(trip);
336
- } else if (trip) {
337
- var _trip = trip,
338
- shots = _trip.shots,
339
- _trip$header = _trip.header,
340
- _azimuthUnit = _trip$header.azimuthUnit,
341
- _inclinationUnit = _trip$header.inclinationUnit;
342
- var _distanceUnit = trip.header.distanceUnit;
343
- var inches = _distanceUnit === _unitized.Length.inches;
344
- if (inches) _distanceUnit = _unitized.Length.feet; // rigorously check the values in all the columns to make sure this
345
- // is really a survey shot line, just in case any stray comments are
346
- // not properly delimited.
347
- // from station name
348
-
349
- if (!/\S/.test(line.substring(5, 10))) return "continue";
350
- var fromStr = validate(5, 10, 'from station', isValidStation); // Sadly I have found negative LRUD values in Chip's format and apparently
351
- // his program doesn't fail on them, so I have to accept them here
352
- // isValidOptFloat instead of isValidOptUFloat
353
-
354
- var lStr = validate(40, 43, 'left', isValidOptFloat);
355
- var rStr = validate(43, 46, 'right', isValidOptFloat);
356
- var uStr = validate(46, 49, 'up', isValidOptFloat);
357
- var dStr = validate(49, 52, 'down', isValidOptFloat);
358
- if (errored) return "continue";
359
- var up = parseLrud(uStr, _distanceUnit);
360
- var down = parseLrud(dStr, _distanceUnit);
361
- var left = parseLrud(lStr, _distanceUnit);
362
- var right = parseLrud(rStr, _distanceUnit); // to station name
363
-
364
- var toStr = line.substring(0, 5);
365
-
366
- if (!toStr.trim()) {
367
- var _shot = {
243
+ _context.next = 107;
244
+ break;
245
+ case 18:
246
+ if (!(line.charAt(0) === '*')) {
247
+ _context.next = 23;
248
+ break;
249
+ }
250
+ inBlockComment = !inBlockComment;
251
+ if (inBlockComment) commentLines = [];else if (commentLines) {
252
+ part = line.substring(1).trim();
253
+ if (part && commentLines) commentLines.push(part);
254
+ }
255
+ _context.next = 107;
256
+ break;
257
+ case 23:
258
+ if (!inBlockComment) {
259
+ _context.next = 27;
260
+ break;
261
+ }
262
+ if (commentLines) commentLines.push(line);
263
+ _context.next = 107;
264
+ break;
265
+ case 27:
266
+ if (!(lineNumber === tripCommentEndLine + 1)) {
267
+ _context.next = 44;
268
+ break;
269
+ }
270
+ // FT CC DD
271
+ // 01234567
272
+ distanceUnit = parseLengthUnit(line.slice(0, 2));
273
+ if (!distanceUnit) {
274
+ distanceUnit = _unitized.Length.feet;
275
+ error('Invalid distance unit', 0, 2);
276
+ }
277
+ azimuthUnit = parseAngleUnit(line[6]);
278
+ if (!azimuthUnit) {
279
+ azimuthUnit = _unitized.Angle.degrees;
280
+ error('Invalid azimuth unit', 6, 7);
281
+ }
282
+ inclinationUnit = parseAngleUnit(line[7]);
283
+ if (!inclinationUnit) {
284
+ inclinationUnit = _unitized.Angle.degrees;
285
+ error('Invalid inclination unit', 7, 8);
286
+ }
287
+ backsightAzimuthCorrected = line[3] === 'C';
288
+ backsightInclinationCorrected = line[4] === 'C';
289
+ hasBacksightAzimuth = line[3] !== ' ' && line[3] !== '-';
290
+ hasBacksightInclination = line[4] !== ' ' && line[4] !== '-';
291
+ if (!/[-CB ]/.test(line[3])) {
292
+ error('Invalid backsight azimuth type', 3, 4);
293
+ }
294
+ if (!/[-CB ]/.test(line[4])) {
295
+ error('Invalid backsight inclination type', 4, 5);
296
+ }
297
+ trip = {
298
+ header: {
299
+ name: tripName || '',
300
+ comment: tripComment && tripComment.join('\n') || null,
301
+ section: section,
302
+ date: tripDate,
303
+ team: tripTeam,
304
+ distanceUnit: distanceUnit,
305
+ azimuthUnit: azimuthUnit,
306
+ inclinationUnit: inclinationUnit,
307
+ backsightAzimuthCorrected: backsightAzimuthCorrected,
308
+ backsightInclinationCorrected: backsightInclinationCorrected,
309
+ hasBacksightAzimuth: hasBacksightAzimuth,
310
+ hasBacksightInclination: hasBacksightInclination
311
+ },
312
+ shots: []
313
+ };
314
+ trips.push(trip);
315
+ _context.next = 107;
316
+ break;
317
+ case 44:
318
+ if (!trip) {
319
+ _context.next = 107;
320
+ break;
321
+ }
322
+ _trip = trip, shots = _trip.shots, _trip$header = _trip.header, _azimuthUnit = _trip$header.azimuthUnit, _inclinationUnit = _trip$header.inclinationUnit;
323
+ _distanceUnit = trip.header.distanceUnit;
324
+ inches = _distanceUnit === _unitized.Length.inches;
325
+ if (inches) _distanceUnit = _unitized.Length.feet;
326
+
327
+ // rigorously check the values in all the columns to make sure this
328
+ // is really a survey shot line, just in case any stray comments are
329
+ // not properly delimited.
330
+
331
+ // from station name
332
+ if (/\S/.test(line.substring(5, 10))) {
333
+ _context.next = 51;
334
+ break;
335
+ }
336
+ return _context.abrupt("return", "continue");
337
+ case 51:
338
+ fromStr = validate(5, 10, 'from station', isValidStation); // Sadly I have found negative LRUD values in Chip's format and apparently
339
+ // his program doesn't fail on them, so I have to accept them here
340
+ // isValidOptFloat instead of isValidOptUFloat
341
+ lStr = validate(40, 43, 'left', isValidOptFloat);
342
+ rStr = validate(43, 46, 'right', isValidOptFloat);
343
+ uStr = validate(46, 49, 'up', isValidOptFloat);
344
+ dStr = validate(49, 52, 'down', isValidOptFloat);
345
+ if (!errored) {
346
+ _context.next = 58;
347
+ break;
348
+ }
349
+ return _context.abrupt("return", "continue");
350
+ case 58:
351
+ up = parseLrud(uStr, _distanceUnit);
352
+ down = parseLrud(dStr, _distanceUnit);
353
+ left = parseLrud(lStr, _distanceUnit);
354
+ right = parseLrud(rStr, _distanceUnit); // to station name
355
+ toStr = line.substring(0, 5);
356
+ if (toStr.trim()) {
357
+ _context.next = 67;
358
+ break;
359
+ }
360
+ _shot = {
368
361
  from: fromStr.trim(),
369
362
  to: null,
370
363
  kind: _FrcsShot.FrcsShotKind.Normal,
@@ -373,214 +366,212 @@ function _parseFrcsSurveyFile() {
373
366
  backsightAzimuth: null,
374
367
  frontsightInclination: null,
375
368
  backsightInclination: null,
376
- left: left,
377
- right: right,
378
- up: up,
379
- down: down,
369
+ fromLruds: {
370
+ left: left,
371
+ right: right,
372
+ up: up,
373
+ down: down
374
+ },
380
375
  excludeDistance: true,
381
376
  comment: getComment()
382
377
  };
383
378
  shots.push(_shot);
384
- return "continue";
385
- }
386
-
387
- if (!isValidStation(toStr)) {
388
- error('Invalid station name', 0, 5);
389
- } // azimuth and inclination
390
-
391
-
392
- var azmFsStr = validate(19, 25, 'azimuth', isValidOptUFloat);
393
- var azmBsStr = validate(25, 30, 'azimuth', isValidOptUFloat);
394
- var incFsStr = line.substring(30, 35);
395
- var incBsStr = line.substring(35, 40);
396
- if (errored) return "continue";
397
- var kind;
398
- var distance;
399
- var horizontalDistance;
400
- var verticalDistance;
401
- var frontsightInclination;
402
- var backsightInclination;
403
- var excludeDistance; // parse distance
404
-
405
- if (inches) {
406
- var feetStr = line.substring(10, 14);
407
- var inchesStr = line.substring(14, 17); // feet and inches are not both optional
379
+ return _context.abrupt("return", "continue");
380
+ case 67:
381
+ if (!isValidStation(toStr)) {
382
+ error('Invalid station name', 0, 5);
383
+ }
384
+ fromLrudMatch = new RegExp("^\\s+".concat(fromStr.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "((\\s+(\\d+(\\.\\d*)?|\\.\\d+)){4})")).exec(line.substring(52));
385
+ if (fromLrudMatch) {
386
+ _fromLrudMatch$1$trim = fromLrudMatch[1].trim().split(/\s+/g).map(function (s) {
387
+ return parseLrud(s, _distanceUnit);
388
+ }), _fromLrudMatch$1$trim2 = (0, _slicedToArray2["default"])(_fromLrudMatch$1$trim, 4), _left = _fromLrudMatch$1$trim2[0], _right = _fromLrudMatch$1$trim2[1], _up = _fromLrudMatch$1$trim2[2], _down = _fromLrudMatch$1$trim2[3];
389
+ fromLruds = {
390
+ left: _left,
391
+ right: _right,
392
+ up: _up,
393
+ down: _down
394
+ };
395
+ }
408
396
 
409
- if (!isValidUInt(feetStr) && !isValidUInt(inchesStr)) {
410
- var invalid = feetStr.trim() || inchesStr.trim();
411
- error(invalid ? 'Invalid distance' : 'Missing distance', 10, 17);
412
- return "continue";
413
- } // sometimes inches are omitted, hence the || 0...I'm assuming it's possible
397
+ // azimuth and inclination
398
+ azmFsStr = validate(19, 25, 'azimuth', isValidOptUFloat);
399
+ azmBsStr = validate(25, 30, 'azimuth', isValidOptUFloat);
400
+ incFsStr = line.substring(30, 35);
401
+ incBsStr = line.substring(35, 40);
402
+ if (!errored) {
403
+ _context.next = 76;
404
+ break;
405
+ }
406
+ return _context.abrupt("return", "continue");
407
+ case 76:
408
+ if (!inches) {
409
+ _context.next = 89;
410
+ break;
411
+ }
412
+ feetStr = line.substring(10, 14);
413
+ inchesStr = line.substring(14, 17); // feet and inches are not both optional
414
+ if (!(!isValidUInt(feetStr) && !isValidUInt(inchesStr))) {
415
+ _context.next = 83;
416
+ break;
417
+ }
418
+ invalid = feetStr.trim() || inchesStr.trim();
419
+ error(invalid ? 'Invalid distance' : 'Missing distance', 10, 17);
420
+ return _context.abrupt("return", "continue");
421
+ case 83:
422
+ // sometimes inches are omitted, hence the || 0...I'm assuming it's possible
414
423
  // for feet to be omitted as well
415
-
416
-
417
424
  distance = _unitized.Unitize.inches(parseFloat(inchesStr) || 0).add(_unitized.Unitize.feet(parseFloat(feetStr) || 0));
418
- kind = parseKind(line[17]); // NOTE there are two columns around here that can contain a *.
425
+ kind = parseKind(line[17]);
426
+ // NOTE there are two columns around here that can contain a *.
419
427
  // I think they might represent different values, but thisis confused by
420
428
  // the fact that for ft/in shots, if there is a D or H flag it occupies the
421
429
  // first column that can contain a * for decimal feet shots
422
-
423
- excludeDistance = line[18] === '*';
424
- } else {
430
+ excludeDistance = line[18] === '*' || line[18] === 's';
431
+ isSplay = line[18] === 's';
432
+ _context.next = 94;
433
+ break;
434
+ case 89:
425
435
  // decimal feet are not optional
426
- var _feetStr = validate(10, 16, 'distance', isValidUFloat);
427
-
436
+ _feetStr = validate(10, 16, 'distance', isValidUFloat);
428
437
  distance = new _unitized.UnitizedNumber(parseFloat(_feetStr), _distanceUnit);
429
438
  kind = parseKind(line[16]);
430
- excludeDistance = line[17] === '*';
431
- }
432
-
433
- if (kind !== _FrcsShot.FrcsShotKind.Normal) {
434
- validate(30, 35, 'vertical-distance', isValidFloat);
435
- } // convert horizontal and diagonal shots to standard
436
- // in this case incFs is the vertical offset between stations
437
- // fortunately it appears we can always count on incFs being specified
438
- // and incBs not being specified for these types of shots
439
-
440
-
441
- if (kind === _FrcsShot.FrcsShotKind.Horizontal) {
442
- // distance is horizontal offset and incFsStr is vertical offset
443
- horizontalDistance = distance;
444
- var h = horizontalDistance.get(_distanceUnit);
445
- var v = parseFloat(incFsStr);
446
- verticalDistance = new _unitized.UnitizedNumber(v, _distanceUnit);
447
- distance = new _unitized.UnitizedNumber(Math.sqrt(h * h + v * v), _distanceUnit);
448
- frontsightInclination = _unitized.Angle.atan2(verticalDistance, horizontalDistance);
449
- backsightInclination = null;
450
- } else if (kind === _FrcsShot.FrcsShotKind.Diagonal) {
451
- // distance is as usual, but incFsStr is vertical offset
452
- var d = distance.get(_distanceUnit);
453
-
454
- var _v = parseFloat(incFsStr);
455
-
456
- verticalDistance = new _unitized.UnitizedNumber(_v, _distanceUnit);
457
- frontsightInclination = _unitized.Angle.asin(_v / d);
458
- backsightInclination = null;
459
- } else {
460
- // frontsight inclination
461
- validate(30, 35, 'inclination', isValidOptInclination); // frontsight inclination
462
-
463
- validate(35, 40, 'inclination', isValidOptInclination);
464
- frontsightInclination = parseNumber(incFsStr, _inclinationUnit);
465
- backsightInclination = parseNumber(incBsStr, _inclinationUnit);
466
- }
467
-
468
- if (errored) return "continue";
469
- var frontsightAzimuth = parseAzimuth(azmFsStr, _azimuthUnit);
470
- var backsightAzimuth = parseAzimuth(azmBsStr, _azimuthUnit);
471
-
472
- if (!frontsightInclination && !backsightInclination) {
473
- frontsightInclination = _unitized.Unitize.degrees(0);
474
- }
439
+ excludeDistance = line[17] === '*' || line[17] === 's';
440
+ isSplay = line[17] === 's';
441
+ case 94:
442
+ if (kind !== _FrcsShot.FrcsShotKind.Normal) {
443
+ validate(30, 35, 'vertical-distance', isValidFloat);
444
+ }
475
445
 
476
- var shot = {
477
- from: fromStr.trim(),
478
- to: toStr.trim(),
479
- kind: kind,
480
- distance: distance,
481
- frontsightAzimuth: frontsightAzimuth,
482
- backsightAzimuth: backsightAzimuth,
483
- frontsightInclination: frontsightInclination,
484
- backsightInclination: backsightInclination,
485
- left: left,
486
- right: right,
487
- up: up,
488
- down: down,
489
- excludeDistance: excludeDistance,
490
- comment: getComment()
491
- };
492
- if (horizontalDistance) shot.horizontalDistance = horizontalDistance;
493
- if (verticalDistance) shot.verticalDistance = verticalDistance;
494
- shots.push(shot);
446
+ // convert horizontal and diagonal shots to standard
447
+ // in this case incFs is the vertical offset between stations
448
+ // fortunately it appears we can always count on incFs being specified
449
+ // and incBs not being specified for these types of shots
450
+ if (kind === _FrcsShot.FrcsShotKind.Horizontal) {
451
+ // distance is horizontal offset and incFsStr is vertical offset
452
+ horizontalDistance = distance;
453
+ h = horizontalDistance.get(_distanceUnit);
454
+ v = parseFloat(incFsStr);
455
+ verticalDistance = new _unitized.UnitizedNumber(v, _distanceUnit);
456
+ distance = new _unitized.UnitizedNumber(Math.sqrt(h * h + v * v), _distanceUnit);
457
+ frontsightInclination = _unitized.Angle.atan2(verticalDistance, horizontalDistance);
458
+ backsightInclination = null;
459
+ } else if (kind === _FrcsShot.FrcsShotKind.Diagonal) {
460
+ // distance is as usual, but incFsStr is vertical offset
461
+ d = distance.get(_distanceUnit);
462
+ _v = parseFloat(incFsStr);
463
+ verticalDistance = new _unitized.UnitizedNumber(_v, _distanceUnit);
464
+ frontsightInclination = _unitized.Angle.asin(_v / d);
465
+ backsightInclination = null;
466
+ } else {
467
+ // frontsight inclination
468
+ validate(30, 35, 'inclination', isValidOptInclination);
469
+ // frontsight inclination
470
+ validate(35, 40, 'inclination', isValidOptInclination);
471
+ frontsightInclination = parseNumber(incFsStr, _inclinationUnit);
472
+ backsightInclination = parseNumber(incBsStr, _inclinationUnit);
473
+ }
474
+ if (!errored) {
475
+ _context.next = 98;
476
+ break;
477
+ }
478
+ return _context.abrupt("return", "continue");
479
+ case 98:
480
+ frontsightAzimuth = parseAzimuth(azmFsStr, _azimuthUnit);
481
+ backsightAzimuth = parseAzimuth(azmBsStr, _azimuthUnit);
482
+ if (!frontsightInclination && !backsightInclination) {
483
+ frontsightInclination = _unitized.Unitize.degrees(0);
484
+ }
485
+ shot = {
486
+ from: fromStr.trim(),
487
+ to: toStr.trim(),
488
+ kind: kind,
489
+ distance: distance,
490
+ frontsightAzimuth: frontsightAzimuth,
491
+ backsightAzimuth: backsightAzimuth,
492
+ frontsightInclination: frontsightInclination,
493
+ backsightInclination: backsightInclination,
494
+ toLruds: {
495
+ left: left,
496
+ right: right,
497
+ up: up,
498
+ down: down
499
+ },
500
+ excludeDistance: excludeDistance,
501
+ comment: getComment()
502
+ };
503
+ if (isSplay) shot.isSplay = true;
504
+ if (fromLruds) shot.fromLruds = fromLruds;
505
+ if (horizontalDistance) shot.horizontalDistance = horizontalDistance;
506
+ if (verticalDistance) shot.verticalDistance = verticalDistance;
507
+ shots.push(shot);
508
+ case 107:
509
+ case "end":
510
+ return _context.stop();
495
511
  }
496
- };
497
-
498
- _iterator = (0, _asyncIterator2["default"])(lines);
499
-
500
- case 18:
501
- _context.next = 20;
502
- return _iterator.next();
503
-
504
- case 20:
505
- _step = _context.sent;
506
- _iteratorNormalCompletion = _step.done;
507
- _context.next = 24;
508
- return _step.value;
509
-
510
- case 24:
511
- _value = _context.sent;
512
-
513
- if (_iteratorNormalCompletion) {
514
- _context.next = 32;
515
- break;
516
- }
517
-
518
- _ret = _loop();
519
-
520
- if (!(_ret === "continue")) {
521
- _context.next = 29;
522
- break;
523
- }
524
-
525
- return _context.abrupt("continue", 29);
526
-
527
- case 29:
528
- _iteratorNormalCompletion = true;
529
- _context.next = 18;
512
+ }, _loop);
513
+ });
514
+ _iterator = _asyncIterator(lines);
515
+ case 18:
516
+ _context2.next = 20;
517
+ return _iterator.next();
518
+ case 20:
519
+ if (!(_iteratorAbruptCompletion = !(_step = _context2.sent).done)) {
520
+ _context2.next = 28;
530
521
  break;
531
-
532
- case 32:
533
- _context.next = 38;
522
+ }
523
+ return _context2.delegateYield(_loop(), "t0", 22);
524
+ case 22:
525
+ _ret = _context2.t0;
526
+ if (!(_ret === "continue")) {
527
+ _context2.next = 25;
534
528
  break;
535
-
536
- case 34:
537
- _context.prev = 34;
538
- _context.t0 = _context["catch"](15);
539
- _didIteratorError = true;
540
- _iteratorError = _context.t0;
541
-
542
- case 38:
543
- _context.prev = 38;
544
- _context.prev = 39;
545
-
546
- if (!(!_iteratorNormalCompletion && _iterator["return"] != null)) {
547
- _context.next = 43;
548
- break;
549
- }
550
-
551
- _context.next = 43;
552
- return _iterator["return"]();
553
-
554
- case 43:
555
- _context.prev = 43;
556
-
557
- if (!_didIteratorError) {
558
- _context.next = 46;
559
- break;
560
- }
561
-
562
- throw _iteratorError;
563
-
564
- case 46:
565
- return _context.finish(43);
566
-
567
- case 47:
568
- return _context.finish(38);
569
-
570
- case 48:
571
- return _context.abrupt("return", {
572
- cave: cave,
573
- location: location,
574
- trips: trips,
575
- errors: errors
576
- });
577
-
578
- case 49:
579
- case "end":
580
- return _context.stop();
581
- }
529
+ }
530
+ return _context2.abrupt("continue", 25);
531
+ case 25:
532
+ _iteratorAbruptCompletion = false;
533
+ _context2.next = 18;
534
+ break;
535
+ case 28:
536
+ _context2.next = 34;
537
+ break;
538
+ case 30:
539
+ _context2.prev = 30;
540
+ _context2.t1 = _context2["catch"](15);
541
+ _didIteratorError = true;
542
+ _iteratorError = _context2.t1;
543
+ case 34:
544
+ _context2.prev = 34;
545
+ _context2.prev = 35;
546
+ if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
547
+ _context2.next = 39;
548
+ break;
549
+ }
550
+ _context2.next = 39;
551
+ return _iterator["return"]();
552
+ case 39:
553
+ _context2.prev = 39;
554
+ if (!_didIteratorError) {
555
+ _context2.next = 42;
556
+ break;
557
+ }
558
+ throw _iteratorError;
559
+ case 42:
560
+ return _context2.finish(39);
561
+ case 43:
562
+ return _context2.finish(34);
563
+ case 44:
564
+ return _context2.abrupt("return", {
565
+ cave: cave,
566
+ location: location,
567
+ trips: trips,
568
+ errors: errors
569
+ });
570
+ case 45:
571
+ case "end":
572
+ return _context2.stop();
582
573
  }
583
- }, _callee, null, [[15, 34, 38, 48], [39,, 43, 47]]);
574
+ }, _callee, null, [[15, 30, 34, 44], [35,, 39, 43]]);
584
575
  }));
585
576
  return _parseFrcsSurveyFile.apply(this, arguments);
586
577
  }