1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! # Data Readers for Site Input Files
//!
//! This module provides utilities for reading site-specific input data into the ground motion
//! prediction library. It focuses on deserializing tabular files into [`Vs30Point`] instances
//! for use in GMPE calculations.
//!
//! ## Features
//!
//! - Load site location and site condition data (longitude, latitude, Vs30, basin depth, and xvf flag).
//! - Support for configurable CSV delimiter characters (e.g., tab, comma).
//! - Assumes no header row in input files.
//!
//! ## Primary Functions
//!
//! - [`read_vs30_points`]: Reads a delimited text file into a vector of [`Vs30Point`] instances.
//!
//! ## Example File Format (tab-delimited)
//!
//! ```text
//! 142.523 52.913 300 250 1
//! 142.600 50.100 350 150 0
//! ```
//!
//! Columns are interpreted as:
//!
//! 1. longitude (f64)
//! 2. latitude (f64)
//! 3. Vs30 (f64)
//! 4. basin depth (optional, f64)
//! 5. xvf flag (optional, u8)
//!
//! ## See Also
//!
//! - [`crate::gmm::Vs30Point`]
//! - [`csv`](https://docs.rs/csv/)
//!
//! ## Errors
//!
//! This module returns boxed errors for I/O issues or data deserialization failures.
use crateVs30Point;
use ReaderBuilder;
use Error;
use File;
use Path;
/// Reads a list of [`Vs30Point`] instances from a delimited text file.
///
/// This function loads site-specific input points for ground motion prediction models from a
/// file. Each line in the file is parsed and deserialized into a [`Vs30Point`] instance, which
/// are collected into a `Vec`.
///
/// The file is assumed to have **no header row**, and the delimiter can be specified to support
/// flexible file formats (e.g., tab, comma, space).
///
/// # Type Parameters
///
/// * `P` — A type convertible to a [`Path`] reference (e.g., `&str`, `PathBuf`).
///
/// # Arguments
///
/// * `path` — Path to the input file.
/// * `delim` — Delimiter character (e.g., `b'\t'` for tab, `b','` for comma).
///
/// # Returns
///
/// A `Result` containing a vector of [`Vs30Point`] instances if successful, or a boxed error
/// if file I/O or parsing fails.
///
/// # Example
///
/// ```rust
/// use ground_motion_lib::readers::read_vs30_points;
///
/// let points = read_vs30_points("tests/data/testvs30.txt", b'\t').unwrap();
/// println!("First point: {:?}", points[0]);
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The file cannot be opened.
/// - Any row in the file fails to deserialize into a [`Vs30Point`].