libcaliph/
lib.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2License, v. 2.0. If a copy of the MPL was not distributed with this
3file, You can obtain one at https://mozilla.org/MPL/2.0/.
4Copyright 2021 Peter Dunne */
5//! A simple tool to calibrate and convert pH measurements using a two point method.
6//! This module contains all the routines necessary to calculate the correction factors needed to calibrate a pH meter.
7//!
8//!## About
9//!
10//!This project contains two binaries:
11//!
12//!`caliph`, for calibrating a pH electrode using a two point pH method.
13//!
14//!`conph` for converting measured pH values to calibrated ones.
15//!
16//!<!-- ## How it works
17//!
18//!Text here -->
19//!
20//!## Demo
21//!
22//!Once installed (see below), the two methods available are:
23//!
24//!### Calibration
25//!
26//!When the temperature is 25˚C during the measurement:
27//!
28//!```console
29//!$ caliph 3.97 10.2
30//!
31//!-----------------
32//!  Calibrating
33//!-----------------
34//!Slope   0.96308
35//!Offset  0.18657
36//!-----------------
37//!
38//!```
39//!
40//!Optional temperature argument:
41//!
42//!```console
43//!$ caliph 3.97 10.2 -t 22.3
44//!
45//!-----------------
46//!  Calibrating
47//!-----------------
48//!Slope   0.96828
49//!Offset  0.16052
50//!-----------------
51//!```
52//!
53//!Boolean flat to save the calibration to `calibration.ph` in the current directory:
54//!
55//!```console
56//!$ caliph 3.97 10.2 -t 22.3 -s
57//!
58//!-----------------
59//!  Calibrating
60//!-----------------
61//!Slope   0.96828
62//!Offset  0.16052
63//!-----------------
64//!
65//!Saved to calibration.ph
66//!```
67//!
68//!## Conversion
69//!
70//!Assuming the `calibration.ph` file exists:
71//!
72//!```console
73//!$ conph 3.5
74//!
75//!---------------
76//!  Converting
77//!---------------
78//!Input   3.5
79//!Output  3.5495
80//!---------------
81//!
82//!```
83//!
84//!Custom calibration settings fof the slope and offset:
85//!
86//!`-c` sets it to custom, `-s VAL` is for the slope, `-o VAL` is for the offset
87//!
88//!```console
89//!$ conph 3.5 -c -s 1.1 -o 0.02
90//!
91//!---------------
92//!  Converting
93//!---------------
94//!Input   3.5
95//!Output  3.8700
96//!---------------
97//!
98//!```
99//!
100//!## Installing
101//!
102//!The latest version of can be installed or updated with `cargo install`:
103//!
104//!```sh
105//!cargo install caliph
106//!```
107//!
108//!or
109//!
110//!```sh
111//!cargo install  --git https://github.com/pdunne/caliph-rs
112//!```
113//!
114//!Binary releases will also be made available on the github page.
115//!
116//!## Compiling
117//!
118//!Follow these instructions to compile `cargo-outdated`, then skip down to Installation.
119//!
120//! 1. Ensure you have current version of `cargo` and [Rust](https://www.rust-lang.org) installed
121//! 2. Clone the project `$ git clone https://github.com/kbknapp/cargo-outdated && cd cargo-outdated`
122//! 3. Build the project `$ cargo build --release`
123//! 4. Once complete, the binary will be located at `target/release/cargo-outdated`
124//!
125//!### Options
126//!
127//!For `caliph`:
128//!
129//!```text
130//!caliph 0.1.3
131//!Peter Dunne
132//!Calculates corrections from 2 point pH calibration
133//!
134//!USAGE:
135//!    caliph [FLAGS] [OPTIONS] <ph4> <ph10>
136//!
137//!FLAGS:
138//!    -h, --help       Prints help information
139//!    -s, --store      Store calibration to file calib.ph
140//!    -V, --version    Prints version information
141//!
142//!OPTIONS:
143//!    -t, --temperature <temperature>    temperature of measurement
144//!
145//!ARGS:
146//!    <ph4>     pH measured for pH 4.01 buffer solution
147//!    <ph10>    pH measured for pH 10.01 buffer solution
148//!```
149//!
150//!and for `conph`
151//!
152//!```text
153//!conph 0.1.3
154//!Peter Dunne
155//!Corrects pH measurement with calibration
156//!
157//!USAGE:
158//!    conph [FLAGS] [OPTIONS] <ph>
159//!
160//!FLAGS:
161//!    -c, --custom     Custom Input
162//!    -h, --help       Prints help information
163//!    -V, --version    Prints version information
164//!
165//!OPTIONS:
166//!    -o, --offset <offset>              Offset
167//!    -s, --slope <slope>                Slope
168//!    -t, --temperature <temperature>    Temperature of measurement
169//!
170//!ARGS:
171//!    <ph>    pH measured
172//!```
173//!
174//!## License
175//!
176//!`calpih-rs` is released under the terms of the Mozilla Public
177//!License, v. 2.0. See the LICENSE.
178//!
179//! For the `caliph` calibration binary, the two imports needed in its main function
180//!  are:
181//! ```
182//! use libcaliph::args::CalibArgs;
183//! use libcaliph::routines::ph_calibration;
184//! ```
185//!
186//! While for `conph` the pH converter, the two imports needed in it's main function are:
187//! ```
188//! use libcaliph::args::CalibArgs;
189//! use libcaliph::routines::ph_convert;
190//! ```
191pub mod args;
192pub mod fit;
193pub mod routines;
194pub mod stats;
195
196/// Temperature points for pH buffer solutions dependent curves.
197///
198/// These are kept in the stack for the lifetime of the program
199static TEMP_STATIC: [f64; 20] = [
200    0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0,
201    80.0, 85.0, 90.0, 95.0,
202];
203
204/// 4.01 pH buffer solutions temperature dependence
205///
206/// This is in the stack for the lifetime of the program
207static PH4_STATIC: [f64; 20] = [
208    4.01, 4., 4., 4., 4., 4.01, 4.02, 4.03, 4.04, 4.05, 4.06, 4.07, 4.09, 4.11, 4.12, 4.14, 4.16,
209    4.17, 4.19, 4.2,
210];
211
212/// 4.01 pH buffer solutions temperature dependence
213///
214/// This is in the stack for the lifetime of the program
215static PH10_STATIC: [f64; 20] = [
216    10.32, 10.25, 10.18, 10.12, 10.06, 10.01, 9.96, 9.92, 9.88, 9.85, 9.82, 9.79, 9.77, 9.76, 9.75,
217    9.74, 9.73, 9.74, 9.75, 9.76,
218];