ldpc_toolbox/cli/
nr5g.rs

1//! 5G NR CLI subcommand.
2//!
3//! This subcommand can be used to generate the LDPC codes used in 5G NR. It
4//! prints the alist of the parity matrix to `stdout`, and optionally computes
5//! and prints the girth of the Tanner graph. Se [`crate::codes::nr5g`] for more
6//! information about the 5G NR LPDC codes.
7//!
8//! # Examples
9//! The base graph 1 with lifting size 32 can be generate with
10//! ```shell
11//! $ ldpc-toolbox 5g --base-graph 1 --lifting-size 32
12//! ```
13//! Its girth is computed with
14//! ```shell
15//! $ ldpc-toolbox 5g --base-graph 1 --lifting-size 32 --girth
16//! ```
17
18use crate::cli::*;
19use crate::codes::nr5g::{BaseGraph, LiftingSize};
20use clap::Parser;
21
22/// 5G NR arguments.
23#[derive(Debug, Parser)]
24pub struct Args {
25    /// Base graph
26    #[arg(long)]
27    pub base_graph: BaseGraph,
28    /// Lifting size
29    #[arg(long)]
30    pub lifting_size: LiftingSize,
31    /// Performs girth calculation
32    #[arg(long)]
33    pub girth: bool,
34}
35
36impl Run for Args {
37    fn run(&self) -> std::result::Result<(), Box<dyn std::error::Error>> {
38        let h = self.base_graph.h(self.lifting_size);
39        if self.girth {
40            if let Some(g) = h.girth() {
41                println!("Code girth = {}", g);
42            } else {
43                println!("Code girth is infinite");
44            }
45        } else {
46            println!("{}", h.alist());
47        }
48        Ok(())
49    }
50}