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