comparison pkg/imports/sr.go @ 2963:27ffd94afcb5

SR import: Limit number of warnings in parsing XYZ files to 100.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 08 Apr 2019 16:51:50 +0200
parents b1707f60f241
children 4acbee65275d
comparison
equal deleted inserted replaced
2962:8d825551bc72 2963:27ffd94afcb5
429 mpz := make(octree.MultiPointZ, 0, 250000) 429 mpz := make(octree.MultiPointZ, 0, 250000)
430 s := bufio.NewScanner(r) 430 s := bufio.NewScanner(r)
431 431
432 var hasNegZ bool 432 var hasNegZ bool
433 433
434 const maxWarnings = 100
435 var warnings int
436
437 warn := func(format string, args ...interface{}) {
438 if warnings++; warnings <= maxWarnings {
439 feedback.Warn(format, args...)
440 }
441 }
442 defer func() {
443 if warnings > maxWarnings {
444 feedback.Warn("Too many warnings. %d ignored.", warnings-maxWarnings)
445 }
446 }()
447
434 for line := 1; s.Scan(); line++ { 448 for line := 1; s.Scan(); line++ {
435 text := s.Text() 449 text := s.Text()
436 var p octree.Vertex 450 var p octree.Vertex
437 // fmt.Sscanf(text, "%f,%f,%f") is 4 times slower. 451 // fmt.Sscanf(text, "%f,%f,%f") is 4 times slower.
438 idx := strings.IndexByte(text, ',') 452 idx := strings.IndexByte(text, ',')
439 if idx == -1 { 453 if idx == -1 {
440 feedback.Warn("format error in line %d", line) 454 warn("format error in line %d", line)
441 continue 455 continue
442 } 456 }
443 var err error 457 var err error
444 if p.X, err = strconv.ParseFloat(text[:idx], 64); err != nil { 458 if p.X, err = strconv.ParseFloat(text[:idx], 64); err != nil {
445 feedback.Warn("format error in line %d: %v", line, err) 459 warn("format error in line %d: %v", line, err)
446 continue 460 continue
447 } 461 }
448 text = text[idx+1:] 462 text = text[idx+1:]
449 if idx = strings.IndexByte(text, ','); idx == -1 { 463 if idx = strings.IndexByte(text, ','); idx == -1 {
450 feedback.Warn("format error in line %d", line) 464 feedback.Warn("format error in line %d", line)
451 continue 465 continue
452 } 466 }
453 if p.Y, err = strconv.ParseFloat(text[:idx], 64); err != nil { 467 if p.Y, err = strconv.ParseFloat(text[:idx], 64); err != nil {
454 feedback.Warn("format error in line %d: %v", line, err) 468 warn("format error in line %d: %v", line, err)
455 continue 469 continue
456 } 470 }
457 text = text[idx+1:] 471 text = text[idx+1:]
458 if p.Z, err = strconv.ParseFloat(text, 64); err != nil { 472 if p.Z, err = strconv.ParseFloat(text, 64); err != nil {
459 feedback.Warn("format error in line %d: %v", line, err) 473 warn("format error in line %d: %v", line, err)
460 continue 474 continue
461 } 475 }
462 if p.Z < 0 { 476 if p.Z < 0 {
463 p.Z = -p.Z 477 p.Z = -p.Z
464 if !hasNegZ { 478 if !hasNegZ {
465 hasNegZ = true 479 hasNegZ = true
466 feedback.Warn("Negative Z value found: Using -Z") 480 warn("Negative Z value found: Using -Z")
467 } 481 }
468 } 482 }
469 mpz = append(mpz, p) 483 mpz = append(mpz, p)
470 } 484 }
471 485