Skip to main content

powerio/format/powerworld/
mod.rs

1//! Read and write PowerWorld auxiliary `.aux` files.
2//!
3//! The reader is layered. [`parse_aux`] parses any auxiliary file into the
4//! generic [`AuxFile`] — every `DATA` and `SCRIPT` section, with field lists,
5//! value rows, and `SUBDATA` blocks intact — and knows the grammar from the
6//! official format guide: legacy and concise headers, comma delimited (CSV)
7//! sections, multiline field lists and value rows, `//` comments, quoting,
8//! and `variablename:location` field suffixes. On top of it, the [`Network`]
9//! mapping consumes the power flow core types (Bus, Load, Shunt, Gen,
10//! Branch) by field name, so column order and extra columns don't matter.
11//! Object types outside the core stay reachable through [`aux_sections`] and
12//! survive the same format round trip byte for byte via the retained source
13//! (see [`crate::write_as`]).
14//!
15//! The writer emits `DATA (Object, [fields]) { … }` blocks for the core
16//! types, values in MW/MVAr/degrees, status as `Closed`/`Open`. Generator
17//! cost, HVDC, and storage are not represented and are reported on write.
18//!
19//! `.pwb` binary cases are read (never written) by [`parse_pwb`]; see that
20//! module for the decoded vintages and the parity evidence. `.pwd` display
21//! files carry no case data, only the diagram; [`parse_pwd_file`] and
22//! [`parse_pwd`] read the decoded substation coordinates.
23//!
24//! [`Network`]: crate::network::Network
25
26mod auxiliary;
27mod map;
28mod objects;
29mod pwb;
30mod pwd;
31
32#[cfg(test)]
33mod tests;
34
35use std::sync::Arc;
36
37pub use auxiliary::{
38    AuxFile, AuxObject, AuxRow, AuxScript, AuxSection, AuxSubData, parse_aux, write_aux,
39};
40pub(crate) use map::parse_powerworld_source;
41pub use map::{aux_sections, write_powerworld};
42pub use objects::{Contingency, contingencies, rating_set_names};
43pub use pwb::parse_pwb;
44pub use pwd::{PwdDisplay, PwdSubstation, parse_pwd, parse_pwd_display, parse_pwd_file};
45
46use crate::Result;
47use crate::network::Network;
48
49/// Parse a PowerWorld `.aux` into a [`Network`], reading the Bus/Load/Shunt/
50/// Gen/Branch `DATA` blocks by their declared field lists.
51///
52/// # Errors
53/// [`crate::Error::FormatRead`] on malformed input or when the file has no
54/// `DATA` sections.
55pub fn parse_powerworld(content: &str) -> Result<Network> {
56    // The caller owns `content` as a borrow, so retention needs one copy.
57    let mut warnings = Vec::new();
58    parse_powerworld_source(Arc::new(content.to_owned()), None, &mut warnings)
59}