pub fn from_text_file<P>(full_path: &P) -> Result<Self, StrError>
    where
        P: AsRef<OsStr> + ?Sized,
    {
        let path = Path::new(full_path).to_path_buf();
        let input = File::open(path).map_err(|_| "cannot open file")?;
        let buffered = BufReader::new(input);
        let mut lines_iter = buffered.lines();

        // auxiliary data structure
        let mut data = DataForReadTextMesh::new();

        // read and parse sizes
        loop {
            match lines_iter.next() {
                Some(v) => {
                    let line = v.unwrap(); // must panic because no error expected here
                    if data.parse_sizes(&line)? {
                        break;
                    }
                }
                None => return Err("file is empty or header is missing"),
            }
        }

        // allocate mesh
        let mut mesh = Mesh {
            ndim: data.ndim,
            points: Vec::new(),
            cells: Vec::new(),
        };

        // read and parse points
        loop {
            match lines_iter.next() {
                Some(v) => {
                    let line = v.unwrap(); // must panic because no error expected here
                    if data.parse_point(&mut mesh, &line)? {
                        if data.current_npoint == data.npoint {
                            break;
                        }
                    }
                }
                None => break,
            }
        }

        // check data
        if data.current_npoint != data.npoint {
            return Err("not all points have been found");
        }

        // read and parse cells
        loop {
            match lines_iter.next() {
                Some(v) => {
                    let line = v.unwrap(); // must panic because no error expected here
                    if data.parse_cell(&mut mesh, &line)? {
                        if data.current_ncell == data.ncell {
                            break;
                        }
                    }
                }
                None => break,
            }
        }

        // check data
        if data.current_ncell != data.ncell {
            return Err("not all cells have been found");
        }

        // done
        Ok(mesh)
    }
/// Allocates a new Mesh by reading raw mesh data from a text file
///
/// # File format
///
/// The text file format includes three sections:
///
/// 1. The header with the space dimension (`ndim`), number of points (`npoint`), and number of cells (`ncell`);
/// 2. The points list where each line contains the `id` of the point, which must be **equal to the position** in the list,
///    followed by the `x` and `y` (and `z`) coordinates;
/// 3. The cells list where each line contains the `id` of the cell, which must be **equal to the position** in the list,
///    the attribute ID (`att`) of the cell, the `kind` of the cell, followed by the IDs of the points that define the cell (connectivity).
///
/// The text file looks like this (the hash tag indicates a comment/the mesh below is just an example which won't work):
///
/// ```text
/// ## header
/// ## ndim npoint ncell
///      2      8     5
///
/// ## points
/// ## id    x   y
///    0  0.0 0.0
///    1  0.5 0.0
///    2  1.0 0.0
/// ## ... more points should follow
///
/// ## cells
/// ## id att kind  point_ids...
///    0   1 tri3  0 1 3
///    1   1 qua4  1 4 6 3
/// ```
///
/// where we can see that different cell (shape) kinds can be present in the same mesh.
/// However, this function does not check for element compatibility as required by finite element analyses.
///
/// See [GeoKind::from] for the keys used to identify the cell kind (the keys are **lowercase**).
///
/// # Input
///
/// * `full_path` -- may be a String, &str, or Path
Allocates a new Mesh by reading raw mesh data from a text file
Allocates a new Mesh by reading raw mesh data from a text file
pub fn from_text_file<P>(full_path: &P) -> Result<Self, StrError>
    where
        P: AsRef<OsStr> + ?Sized,
    {
        let path = Path::new(full_path).to_path_buf();
        let input = File::open(path).map_err(|_| "cannot open file")?;
        let buffered = BufReader::new(input);
        let mut lines_iter = buffered.lines();
        // auxiliary data structure
        let mut data = DataForReadTextMesh::new();
        // read and parse sizes
        loop {
            match lines_iter.next() {
                Some(v) => {
                    let line = v.unwrap(); // must panic because no error expected here
                    if data.parse_sizes(&line)? {
                        break;
                    }
                }
                None => return Err("file is empty or header is missing"),
            }
        }
        // allocate mesh
        let mut mesh = Mesh {
            ndim: data.ndim,
            points: Vec::new(),
            cells: Vec::new(),
        };
        // read and parse points
        loop {
            match lines_iter.next() {
                Some(v) => {
                    let line = v.unwrap(); // must panic because no error expected here
                    if data.parse_point(&mut mesh, &line)? {
                        if data.current_npoint == data.npoint {
                            break;
                        }
                    }
                }
                None => break,
            }
        }
        // check data
        if data.current_npoint != data.npoint {
            return Err("not all points have been found");
        }
        // read and parse cells
        loop {
            match lines_iter.next() {
                Some(v) => {
                    let line = v.unwrap(); // must panic because no error expected here
                    if data.parse_cell(&mut mesh, &line)? {
                        if data.current_ncell == data.ncell {
                            break;
                        }
                    }
                }
                None => break,
            }
        }
        // check data
        if data.current_ncell != data.ncell {
            return Err("not all cells have been found");
        }
        // done
        Ok(mesh)
    }
pub fn from_text_file < P > ( full_path : & P ) -> Result < Self , StrError > where P : AsRef < OsStr > + ? Sized , { let path = Path :: new ( full_path ) . to_path_buf ( ) ; let input = File :: open ( path ) . map_err ( | _ | " " ) ? ; let buffered = BufReader :: new ( input ) ; let mut lines_iter = buffered . lines ( ) ; // auxiliary data structure let mut data = DataForReadTextMesh :: new ( ) ; // read and parse sizes loop { match lines_iter . next ( ) { Some ( v ) => { let line = v . unwrap ( ) ; // must panic because no error expected here if data . parse_sizes ( & line ) ? { break ; } } None => return Err ( " " ) , } } // allocate mesh let mut mesh = Mesh { ndim : data . ndim , points : Vec :: new ( ) , cells : Vec :: new ( ) , } ; // read and parse points loop { match lines_iter . next ( ) { Some ( v ) => { let line = v . unwrap ( ) ; // must panic because no error expected here if data . parse_point ( & mut mesh , & line ) ? { if data . current_npoint == data . npoint { break ; } } } None => break , } } // check data if data . current_npoint != data . npoint { return Err ( " " ) ; } // read and parse cells loop { match lines_iter . next ( ) { Some ( v ) => { let line = v . unwrap ( ) ; // must panic because no error expected here if data . parse_cell ( & mut mesh , & line ) ? { if data . current_ncell == data . ncell { break ; } } } None => break , } } // check data if data . current_ncell != data . ncell { return Err ( " " ) ; } // done Ok ( mesh ) }
Allocates a new Mesh by reading raw mesh data from a text file
Allocates a new Mesh by reading raw mesh data from a text file
full_path
&P
full_path
&P
file format
The text file format includes three sections.

1. The header with the space dimension (`ndim`), number of points (`npoint`), and number of cells (`ncell`);
2. The points list where each line contains the `id` of the point, which must be **equal to the position** in the list,
followed by the `x` and `y` (and `z`) coordinates;
3. The cells list where each line contains the `id` of the cell, which must be **equal to the position** in the list,
the attribute ID (`att`) of the cell, the `kind` of the cell, followed by the IDs of the points that define the cell (connectivity).

The text file looks like this (the hash tag indicates a comment/the mesh below is just an example which won't work).


The text file format includes three sections . 1 . The header with the space dimension ( ` ndim ` ) number of points ( ` npoint ` ) and number of cells ( ` ncell ` ) ; 2 . The points list where each line contains the ` id ` of the point which must be ** equal to the position ** in the list followed by the ` x ` and ` y ` ( and ` z ` ) coordinates ; 3 . The cells list where each line contains the ` id ` of the cell which must be ** equal to the position ** in the list the attribute ID ( ` att ` ) of the cell the ` kind ` of the cell followed by the IDs of the points that define the cell ( connectivity ) . The text file looks like this ( the hash tag indicates a comment / the mesh below is just an example which won ' t work ) .
header
None
ndim npoint ncell
2      8     5
2 8 5
points
None
id    x   y
None
... more points should follow
None
cells
None
id att kind  point_ids...




See [GeoKind::from] for the keys used to identify the cell kind (the keys are **lowercase**).
See [ GeoKind :: from ] for the keys used to identify the cell kind ( the keys are ** lowercase ** ) .
input
`full_path` -- may be a String, &str, or Path
` full_path ` -- may be a String &str or Path