2 unstable releases

0.2.0 Jul 8, 2021
0.1.0 Jul 8, 2021

#1246 in Algorithms

MIT/Apache

170KB
4.5K SLoC

IO Example

Read file:

use citi::Record;
use std::fs::File;

let mut file = File::open("file.cti").unwrap();
let record = Record::from_reader(&mut file);

Write file:

use citi::Record;
use std::fs::File;

let record = Record::default();
let mut file = File::create("file.cti").unwrap();
record.to_writer(&mut file);

lib.rs:

Input/Output for CITI records

The standard, defines the following entities:

Name Description
Record The entire contents of the record
Header Header of the record
Data One or more data arrays
Keyword Define the header contents

As this is a custom ASCII record type, the standard is not as simple as one would like. The standard is followed as closely as is reasonable. The largest changes are in the extension of the keywords.

Non-Standard Type

A non-standard but industry prevelent comment section is added formated with a bang:

!COMMENT

These are used to provide internal comments.

IO Example

The object must implement the BufRead trait since CITI files are read line-by-line. As a result, two reads will lead to a fail on the second read, since the buffer is empty.

Read file:

use citi::Record;
use std::fs::File;

let mut file = File::open("file.cti").unwrap();
let record = Record::from_reader(&mut file);

Write file:

use citi::Record;
use std::fs::File;

let record = Record::default();
let mut file = File::create("file.cti").unwrap();
record.to_writer(&mut file);

Input-Output Consistency:

General input-output consistency cannot be guaranteed with CITI records because of their design. That is, if a record is read in and read out, the byte representation of the record may change, exact floating point representations may change, but the record will contain the same information. The following is not guaranteed:

  • ASCII representation of floating points may change because of the String -> Float -> String conversion.
  • Floats may be shifted in exponential format.
  • All SEG_LIST keywords will be converted to VAR_LIST

Dependencies

~2.7–4MB
~76K SLoC