Skip to content

Commit

Permalink
Merge pull request #220 from cjordan/failure->thiserror
Browse files Browse the repository at this point in the history
failure -> thiserror/anyhow
  • Loading branch information
pkgw authored Jan 20, 2023
2 parents 8a8e6d8 + 91713bc commit b826979
Show file tree
Hide file tree
Showing 32 changed files with 785 additions and 545 deletions.
195 changes: 87 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions casatables/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ rubbl_casatables_impl = "thiscommit:2021-11-04:9Lgzrtq"
rubbl_core = "thiscommit:2020-12-15:EiT8sa0a"

[dependencies]
failure = "^0.1"
failure_derive = "^0.1"
ndarray = ">=0.8"
ndarray = "0.15.0"
rubbl_casatables_impl = { version ="0.0.0-dev.0", path = "../casatables_impl" }
rubbl_core = { version ="0.0.0-dev.0", path = "../core" }
thiserror = "1.0.7"

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
cc = { version = "1.0.42", features = ["parallel"] }

[dev-dependencies]
clap = { version = "^4", features = ["cargo"] }
tempfile = "3.3"
anyhow = "1.0.0"
clap = { version = "4.0.26", features = ["cargo"] }
rubbl_core = { version ="0.0.0-dev.0", path = "../core", features = ["notifications"] }
tempfile = "3.3.0"
6 changes: 6 additions & 0 deletions casatables/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# `rubbl_casatables`

A Rust interface to the CASA table format.

See [the `rubbl_core` README on Crates.io][1] for a discussion of crate
duplication issues that may arise with key dependencies such as [`ndarray`][2].

[1]: https://crates.io/crates/rubbl_core/
[2]: https://crates.io/crates/ndarray/
29 changes: 19 additions & 10 deletions casatables/examples/tableinfo.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2017 Peter Williams <[email protected]> and collaborators
// Copyright 2017-2023 Peter Williams <[email protected]> and collaborators
// Licensed under the MIT License.

//! Summarize the structure of a CASA table.
use anyhow::Error;
use clap::{Arg, Command};
use rubbl_casatables::{Table, TableOpenMode};
use rubbl_core::{ctry, notify::ClapNotificationArgsExt, Error};
use rubbl_core::{ctry, notify::ClapNotificationArgsExt};
use std::{cmp::max, path::PathBuf, process};

fn main() {
Expand All @@ -25,24 +26,30 @@ fn main() {
|matches, _nbe| -> Result<i32, Error> {
let inpath = matches.get_one::<PathBuf>("IN-TABLE").unwrap();

let mut t = ctry!(Table::open(&inpath, TableOpenMode::Read);
"failed to open input table \"{}\"", inpath.display());
let mut t = ctry!(
Table::open(&inpath, TableOpenMode::Read);
"failed to open input table \"{}\"", inpath.display()
);

println!("Table \"{}\":", inpath.display());
println!("Number of rows: {}", t.n_rows());
println!("Number of columns: {}", t.n_columns());
println!("");

let col_names = ctry!(t.column_names();
"failed to get names of columns in \"{}\"", inpath.display());
let col_names = ctry!(
t.column_names();
"failed to get names of columns in \"{}\"", inpath.display()
);

let mut max_name_len = 0;
let mut max_type_len = 0;
let mut info: Vec<(&str, String, String)> = Vec::new();

for n in &col_names {
let desc = ctry!(t.get_col_desc(&n);
"failed to query column \"{}\" in \"{}\"", n, inpath.display());
let desc = ctry!(
t.get_col_desc(&n);
"failed to query column \"{}\" in \"{}\"", n, inpath.display()
);

let type_text = format!("{}", desc.data_type());

Expand All @@ -67,8 +74,10 @@ fn main() {
);
}

let table_kw_names = ctry!(t.table_keyword_names();
"failed to get keyword info in \"{}\"", inpath.display());
let table_kw_names = ctry!(
t.table_keyword_names();
"failed to get keyword info in \"{}\"", inpath.display()
);

if table_kw_names.len() != 0 {
println!();
Expand Down
36 changes: 25 additions & 11 deletions casatables/src/glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ extern "C" {
const casacore::RecordDesc &desc = rec.description();
casacore::Int field_num = rec.fieldNumber(bridge_string(col_name));

if (field_num < 0)
throw std::runtime_error("unrecognized column name");
if (field_num < 0) {
std::string s = "unrecognized column name: ";
s.append(bridge_string(col_name));
throw std::runtime_error(s);
}

*data_type = rec.type(field_num);

Expand Down Expand Up @@ -289,8 +292,11 @@ extern "C" {
casacore::Int field_num = rec.fieldNumber(bridge_string(field_name));
casacore::IPosition shape;

if (field_num < 0)
throw std::runtime_error("unrecognized keyword name");
if (field_num < 0) {
std::string s = "unrecognized keyword name: ";
s.append(bridge_string(field_name));
throw std::runtime_error(s);
}

if (!desc.isScalar(field_num)) {
shape = rec.shape(field_num);
Expand Down Expand Up @@ -369,8 +375,11 @@ extern "C" {
try {
casacore::Int field_num = rec.fieldNumber(bridge_string(col_name));

if (field_num < 0)
throw std::runtime_error("unrecognized keyword name");
if (field_num < 0) {
std::string s = "unrecognized keyword name: ";
s.append(bridge_string(col_name));
throw std::runtime_error(s);
}

if (rec.type(field_num) != casacore::TpString)
throw std::runtime_error("tablerec cell must be of TpString type");
Expand Down Expand Up @@ -398,8 +407,11 @@ extern "C" {
try {
casacore::Int field_num = rec.fieldNumber(bridge_string(col_name));

if (field_num < 0)
throw std::runtime_error("unrecognized column name");
if (field_num < 0) {
std::string s = "unrecognized column name: ";
s.append(bridge_string(col_name));
throw std::runtime_error(s);
}

casacore::IPosition shape = rec.shape(field_num);

Expand Down Expand Up @@ -428,9 +440,11 @@ extern "C" {
try {
casacore::Int field_num = rec.fieldNumber(bridge_string(col_name));

if (field_num < 0)
throw std::runtime_error("unrecognized column name");

if (field_num < 0) {
std::string s = "unrecognized column name: ";
s.append(bridge_string(col_name));
throw std::runtime_error(s);
}

if (rec.type(field_num) != casacore::TpRecord)
throw std::runtime_error("row cell must be of TpRecord type");
Expand Down
Loading

0 comments on commit b826979

Please sign in to comment.