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
//! # Data Writers for GMPE Output Files
//!
//! This module provides utilities for writing ground motion prediction results
//! (as [`GmpePoint`] instances) to delimited text files.
//!
//! ## Features
//!
//! - Serialize computed GMPE values for site points into CSV or other delimited formats.
//! - Configurable delimiter support (e.g., tab, comma).
//! - Optionally writes header rows.
//!
//! ## Primary Functions
//!
//! - [`write_gmpe_points`]: Writes a vector of [`GmpePoint`] instances to a delimited file.
//!
//! ## Example Output Format (tab-delimited)
//!
//! ```text
//! lon lat value kind
//! 142.600 50.100 0.789 Pga
//! 142.700 50.200 0.923 Pga
//! ```
//!
//! ## See Also
//!
//! - [`crate::gmm::GmpePoint`]
//! - [`csv`](https://docs.rs/csv/)
use crateGmpePoint;
use WriterBuilder;
use Error;
use File;
use Path;
/// Writes a list of [`GmpePoint`] instances to a delimited text file.
///
/// This function serializes a list of ground motion prediction results into a file
/// with a configurable delimiter. Each [`GmpePoint`] is written as a CSV row,
/// including a header row describing the columns.
///
/// # Type Parameters
///
/// * `P` — A type convertible to a [`Path`] reference (e.g., `&str`, `PathBuf`).
///
/// # Arguments
///
/// * `path` — The output file path.
/// * `delim` — Delimiter character for the file (e.g., `b','` for comma, `b'\t'` for tab).
/// * `points` — A slice of [`GmpePoint`] instances to write.
///
/// # Returns
///
/// * `Ok(())` if writing was successful.
/// * An error boxed as `Box<dyn Error>` if file I/O or serialization fails.
///
/// # Example
///
/// ```rust
/// use ground_motion_lib::writers::write_gmpe_points;
/// use ground_motion_lib::gmm::{GmpePoint, GmpePointKind};
///
/// let points = vec![
/// GmpePoint { lon: 10.0, lat: 20.0, value: 0.5, kind: GmpePointKind::Pga },
/// GmpePoint { lon: 15.0, lat: 25.0, value: 0.8, kind: GmpePointKind::Pga },
/// ];
///
/// write_gmpe_points("output.csv", b'\t', &points).unwrap();
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The file cannot be created or opened.
/// - Any [`GmpePoint`] instance fails to serialize.