asp_lib/
lib.rs

1#![feature(iter_next_chunk)]
2#![feature(absolute_path)]
3#![feature(path_file_prefix)]
4
5pub mod helper_funcs;
6mod spectra;
7mod spectrum;
8use helper_funcs::handle_one_file;
9
10use spectra::Spectra;
11use std::error::Error;
12use std::path:: Path;
13
14/// Parses a directory `path` (subdirectories included)., finds all .asp files contained
15/// within, and generates the same folder structure with converted .csv files in `export_path`
16/// # Examples
17///
18/// ```
19/// use asp_lib::handle_many_spectra;
20/// handle_many_spectra(".", "./exported files")
21/// ```
22pub fn handle_many_spectra(
23    path: &str,
24    export_path: &str,
25) -> Result<String, Box<dyn std::error::Error>> {
26    let spectra = Spectra::build_from_path(path, export_path)?;
27    spectra.export_all();
28    Ok(String::from(path))
29}
30
31/// Converts a single .asp file into .csv. It also adds the corresponding wavenumber column
32/// # Examples
33///
34/// ```
35/// use asp_lib::handle_single_spectrum;
36/// # to generate ./exported/file.csv
37/// handle_single_spectrum("file.asp", "./exported")
38/// ```
39pub fn handle_single_spectrum(
40    filepath: &str,
41    savepath: &str,
42) -> Result<String, Box<dyn std::error::Error>> {
43    let mut spectrum = handle_one_file(filepath, None)?;
44    spectrum.to_csv(savepath)?;
45    Ok(String::from(filepath))
46}