diff --git a/Cargo.toml b/Cargo.toml index 748efd0..7238924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ exclude = ["crates/wasm"] [dependencies] num = "0.4.1" nom = "7.1.3" +log = "0.4" quick-error = "2.0.1" healpix = { package = "cdshealpix", version = "0.7" } mapproj = "0.3" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 38d5dd8..70d0a65 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -21,6 +21,7 @@ bench = false test = false [dependencies] +log = "0.4" moclib = { package = "moc", path = "../.." } num = "0.4" structopt = "0.3" diff --git a/crates/cli/src/from.rs b/crates/cli/src/from.rs index 402bbd0..cb2b498 100644 --- a/crates/cli/src/from.rs +++ b/crates/cli/src/from.rs @@ -8,6 +8,7 @@ use std::{ str::{self, FromStr}, }; +use log::error; use structopt::StructOpt; use healpix::nested::Layer; @@ -440,7 +441,7 @@ impl From { move |line: std::io::Result| match line2cone_params(&separator, line) { Ok(lonlatrad) => Some(lonlatrad), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -734,7 +735,7 @@ impl From { let line2moc = move |line: std::io::Result| match line2m(depth, &separator, line) { Ok(moc) => Some(moc), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -783,7 +784,7 @@ impl From { let line2pos = move |line: std::io::Result| match line2coos(&separator, line) { Ok(lonlat) => Some(lonlat), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -873,7 +874,7 @@ impl From { ) { Ok(uniq_val_dens) => Some(uniq_val_dens), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -903,7 +904,7 @@ impl From { move |line: std::io::Result| match line2uvd_from_val(&separator, depth, line) { Ok(uniq_val_dens) => Some(uniq_val_dens), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -998,7 +999,7 @@ impl From { { Ok(t) => Some(t), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -1050,7 +1051,7 @@ impl From { move |line: std::io::Result| match line2tr(&separator, &time, line) { Ok(trange) => Some(trange), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -1116,7 +1117,7 @@ impl From { ) { Ok(lonlat) => Some(lonlat), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -1183,7 +1184,7 @@ impl From { move |line: std::io::Result| match line2trcoos(&separator, &time, layer, line) { Ok(lonlat) => Some(lonlat), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -1211,11 +1212,11 @@ impl From { let line2freq = move |line: std::io::Result| match line.map(|s| s.parse::()) { Ok(Ok(f)) => Some(f), Ok(Err(e)) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; @@ -1264,7 +1265,7 @@ impl From { let line2trange = move |line: std::io::Result| match line2tr(&separator, line) { Ok(trange) => Some(trange), Err(e) => { - eprintln!("Error reading or parsing line: {:?}", e); + error!("Error reading or parsing line: {:?}", e); None } }; diff --git a/crates/set/Cargo.toml b/crates/set/Cargo.toml index 72877a0..fe4b503 100644 --- a/crates/set/Cargo.toml +++ b/crates/set/Cargo.toml @@ -21,6 +21,7 @@ bench = false test = false [dependencies] +log = "0.4" moclib = { package = "moc", path = "../.." } cdshealpix = "0.6.8" memmap = { package = "memmap2", version = "0.5" } diff --git a/crates/set/src/mk.rs b/crates/set/src/mk.rs index dc3b4c0..19bd471 100644 --- a/crates/set/src/mk.rs +++ b/crates/set/src/mk.rs @@ -7,6 +7,7 @@ use std::{ use byteorder::{LittleEndian, WriteBytesExt}; use clap::Parser; +use log::warn; use memmap::MmapMut; use moclib::{ @@ -66,7 +67,7 @@ impl Make { .enumerate() .filter_map(|(i, line)| match line.trim().split_once(self.separator) { None => { - eprintln!( + warn!( "Line {} ignored. No delimiter '{}' found in {}.", i, self.separator, line ); @@ -75,7 +76,7 @@ impl Make { Some((id, path)) => match id.trim().parse::() { Ok(id) => Some((id, PathBuf::from(path.trim()))), Err(e) => { - eprintln!( + warn!( "Line {} ignored. Error parsing identifier '{}': {}", i, id, e ); @@ -145,7 +146,7 @@ impl Make { // TODO/WARNING: part of code duplicated with 'append.rs' => to be clean (e.g. passing a closure)! from_byte = match from_fits_file(path.clone()) { Err(e) => { - eprintln!("MOC id: {}; path: {:?}; ignored. Cause: {:?}", id, path, e); + warn!("MOC id: {}; path: {:?}; ignored. Cause: {:?}", id, path, e); from_byte } Ok(MocIdxType::>::U16(MocQtyType::>::Hpx(moc))) => { @@ -204,7 +205,7 @@ impl Make { } } _ => { - eprintln!( + warn!( "MOC id: {}; path: {:?}; ignored. Cause: MOC type not supported.", id, path ); diff --git a/crates/set/tests/integration.rs b/crates/set/tests/integration.rs index 1387d4f..61b6628 100644 --- a/crates/set/tests/integration.rs +++ b/crates/set/tests/integration.rs @@ -11,7 +11,7 @@ fn integration_test() { .arg("cd resources/tests && ./test.bash") .output() .expect("failed to execute process"); - // eprintln!("Stderr: {:?}", String::from_utf8(output.stderr)); + // println!("Stderr: {:?}", String::from_utf8(output.stderr)); assert!(output.status.success(), "Output status: {}", output.status); // We double check to be sure that we reach the end of the script assert_eq!(output.stdout, b"Everything seems OK :)\n"); diff --git a/src/deser/ascii.rs b/src/deser/ascii.rs index b7a5801..bf80c50 100644 --- a/src/deser/ascii.rs +++ b/src/deser/ascii.rs @@ -1,31 +1,37 @@ -use std::io::{self, BufRead, Lines, Write}; -use std::marker::PhantomData; -use std::str::FromStr; +use std::{ + io::{self, BufRead, Lines, Write}, + marker::PhantomData, + str::FromStr, +}; use byteorder::WriteBytesExt; +use log::error; use quick_error::quick_error; -use nom::branch::alt; -use nom::character::complete::char; -use nom::character::complete::{digit1, multispace0}; -use nom::combinator::{cut, map, map_res, opt}; -use nom::error::{convert_error, FromExternalError, ParseError, VerboseError}; -use nom::multi::many1; -use nom::sequence::{preceded, terminated, tuple}; -use nom::IResult; - -use crate::elem::{cell::Cell, cellcellrange::CellOrCellRange, cellrange::CellRange}; -use crate::elemset::cellcellrange::{CellOrCellRanges, MocCellOrCellRanges}; -use crate::idx::Idx; -use crate::moc::{ - cellcellrange::CellOrCellRangeMOC, CellOrCellRangeMOCIterator, HasMaxDepth, MOCProperties, - NonOverlapping, ZSorted, +use nom::{ + branch::alt, + character::complete::{char, digit1, multispace0}, + combinator::{cut, map, map_res, opt}, + error::{convert_error, FromExternalError, ParseError, VerboseError}, + multi::many1, + sequence::{preceded, terminated, tuple}, + IResult, }; -use crate::moc2d::{ - cellcellrange::{CellOrCellRangeMOC2, CellOrCellRangeMOC2Elem}, - CellOrCellRangeMOC2ElemIt, CellOrCellRangeMOC2Iterator, + +use crate::{ + elem::{cell::Cell, cellcellrange::CellOrCellRange, cellrange::CellRange}, + elemset::cellcellrange::{CellOrCellRanges, MocCellOrCellRanges}, + idx::Idx, + moc::{ + cellcellrange::CellOrCellRangeMOC, CellOrCellRangeMOCIterator, HasMaxDepth, MOCProperties, + NonOverlapping, ZSorted, + }, + moc2d::{ + cellcellrange::{CellOrCellRangeMOC2, CellOrCellRangeMOC2Elem}, + CellOrCellRangeMOC2ElemIt, CellOrCellRangeMOC2Iterator, + }, + qty::MocQty, }; -use crate::qty::MocQty; quick_error! { #[derive(Debug)] @@ -539,9 +545,9 @@ impl, R: BufRead> Iterator for MOCFromAsciiStream return Some(CellOrCellRange::Cell(Cell::new(depth, idx))); } } - eprintln!("Error parsing ascii stream at line: {:?}", line); + error!("Error parsing ascii stream at line: {:?}", line); } - _ => eprintln!( + _ => error!( "Error parsing ascii stream at line: {:?}. Separator '/' not found.", line ), @@ -549,7 +555,7 @@ impl, R: BufRead> Iterator for MOCFromAsciiStream } } Ok(None) => return None, - Err(e) => eprintln!("Error reading ascii stream: {:?}", e), + Err(e) => error!("Error reading ascii stream: {:?}", e), } } } diff --git a/src/deser/fits/mod.rs b/src/deser/fits/mod.rs index a3622d7..4aba2d4 100644 --- a/src/deser/fits/mod.rs +++ b/src/deser/fits/mod.rs @@ -1,41 +1,45 @@ //! This module deals with MOC serialization/deserialization in the //! [FITS standard](https://fits.gsfc.nasa.gov/standard40/fits_standard40aa-le.pdf). -use std::io::{BufRead, Cursor, Write}; -use std::marker::PhantomData; -use std::ops::Range; +use std::{ + io::{BufRead, Cursor, Write}, + marker::PhantomData, + ops::Range, +}; use byteorder::BigEndian; +use log::warn; -use crate::deser::fits::{ - common::{ - check_keyword_and_parse_uint_val, check_keyword_and_val, consume_primary_hdu, - next_36_chunks_of_80_bytes, write_primary_hdu, write_uint_mandatory_keyword_record, +use crate::{ + deser::fits::{ + common::{ + check_keyword_and_parse_uint_val, check_keyword_and_val, consume_primary_hdu, + next_36_chunks_of_80_bytes, write_primary_hdu, write_uint_mandatory_keyword_record, + }, + error::FitsError, + keywords::{ + CoordSys, FitsCard, MocDim, MocId, MocKeywords, MocKeywordsMap, MocOrdF, MocOrdS, MocOrdT, + MocOrder, MocTool, MocVers, Ordering, TForm1, TType1, TimeSys, + }, }, - error::FitsError, - keywords::{ - CoordSys, FitsCard, MocDim, MocId, MocKeywords, MocKeywordsMap, MocOrdF, MocOrdS, MocOrdT, - MocOrder, MocTool, MocVers, Ordering, TForm1, TType1, TimeSys, + elem::cell::Cell, + elemset::{ + cell::{Cells, MocCells}, + range::MocRanges, }, + idx::Idx, + moc::{ + cell::CellMOC, + range::{op::convert::convert_to_u64, RangeMOC, RangeMocIter}, + CellMOCIntoIterator, CellMOCIterator, HasMaxDepth, MOCProperties, NonOverlapping, + RangeMOCIterator, ZSorted, + }, + moc2d::{ + range::{RangeMOC2, RangeMOC2Elem}, + HasTwoMaxDepth, MOC2Properties, RangeMOC2ElemIt, RangeMOC2IntoIterator, RangeMOC2Iterator, + }, + qty::{Frequency, Hpx, MocQty, MocableQty, Time}, }; -use crate::elem::cell::Cell; -use crate::elemset::{ - cell::{Cells, MocCells}, - range::MocRanges, -}; -use crate::idx::Idx; -use crate::moc::range::op::convert::convert_to_u64; -use crate::moc::{ - cell::CellMOC, - range::{RangeMOC, RangeMocIter}, - CellMOCIntoIterator, CellMOCIterator, HasMaxDepth, MOCProperties, NonOverlapping, - RangeMOCIterator, ZSorted, -}; -use crate::moc2d::{ - range::{RangeMOC2, RangeMOC2Elem}, - HasTwoMaxDepth, MOC2Properties, RangeMOC2ElemIt, RangeMOC2IntoIterator, RangeMOC2Iterator, -}; -use crate::qty::{Frequency, Hpx, MocQty, MocableQty, Time}; pub mod common; pub mod error; @@ -594,7 +598,10 @@ pub fn from_fits_ivoa_custom( if let Some(previous_mkw) = moc_kws.insert(mkw?) { // A FITS keyword MUST BE uniq (I may be more relax here, taking the last one and not complaining) // return Err(FitsError::MultipleKeyword(previous_mkw.keyword_str().to_string())) - eprintln!("WARNING: Keyword '{}' found more than once in a same HDU! We use the first occurrence.", previous_mkw.keyword_str()); + warn!( + "Keyword '{}' found more than once in a same HDU! We use the first occurrence.", + previous_mkw.keyword_str() + ); moc_kws.insert(previous_mkw); } // else keyword added without error @@ -993,8 +1000,8 @@ where R: BufRead, { if depth_max > Hpx::::MAX_DEPTH { - eprintln!( - "WARNING: Wrong depth_max {}. Reset to {}", + warn!( + "Wrong depth_max {}. Reset to {}", depth_max, Hpx::::MAX_DEPTH ); diff --git a/src/deser/fits/multiordermap.rs b/src/deser/fits/multiordermap.rs index 97f984a..66a8f98 100644 --- a/src/deser/fits/multiordermap.rs +++ b/src/deser/fits/multiordermap.rs @@ -4,6 +4,7 @@ use std::{ }; use byteorder::{BigEndian, ReadBytesExt}; +use log::warn; use crate::{ deser::{ @@ -215,7 +216,10 @@ impl MultiOrderMapIterator { if let Some(previous_mkw) = moc_kws.insert(mkw?) { // A FITS keyword MUST BE uniq (I may be more relax here, taking the last one and not complaining) // return Err(FitsError::MultipleKeyword(previous_mkw.keyword_str().to_string())) - eprintln!("WARNING: Keyword '{}' found more than once in a same HDU! We use the first occurrence.", previous_mkw.keyword_str()); + warn!( + "Keyword '{}' found more than once in a same HDU! We use the first occurrence.", + previous_mkw.keyword_str() + ); moc_kws.insert(previous_mkw); } // else keyword added without error diff --git a/src/deser/fits/skymap.rs b/src/deser/fits/skymap.rs index 71a8be9..f1a427f 100644 --- a/src/deser/fits/skymap.rs +++ b/src/deser/fits/skymap.rs @@ -1,25 +1,31 @@ -use std::io::{self, BufRead, BufReader, Read, Seek}; -use std::mem::size_of; +use std::{ + io::{self, BufRead, BufReader, Read, Seek}, + mem::size_of, +}; use byteorder::{BigEndian, ReadBytesExt}; +use log::warn; + use healpix::depth; -use crate::deser::{ - fits::{ - common::{ - check_keyword_and_get_str_val, check_keyword_and_parse_uint_val, check_keyword_and_val, - consume_primary_hdu, next_36_chunks_of_80_bytes, +use crate::{ + deser::{ + fits::{ + common::{ + check_keyword_and_get_str_val, check_keyword_and_parse_uint_val, check_keyword_and_val, + consume_primary_hdu, next_36_chunks_of_80_bytes, + }, + error::FitsError, + keywords::{FitsCard, IndexSchema, MocKeywords, MocKeywordsMap, MocOrder, Nside, Ordering}, }, - error::FitsError, - keywords::{FitsCard, IndexSchema, MocKeywords, MocKeywordsMap, MocOrder, Nside, Ordering}, + gz::{is_gz, uncompress}, }, - gz::{is_gz, uncompress}, -}; -use crate::elem::{ - cell::Cell, cellrange::CellRange, range::MocRange, valuedcell::valued_cells_to_moc_with_opt, + elem::{ + cell::Cell, cellrange::CellRange, range::MocRange, valuedcell::valued_cells_to_moc_with_opt, + }, + moc::range::RangeMOC, + qty::Hpx, }; -use crate::moc::range::RangeMOC; -use crate::qty::Hpx; /// We expect the FITS file to be a BINTABLE containing a skymap. /// [Here](https://gamma-astro-data-formats.readthedocs.io/en/latest/skymaps/healpix/index.html) @@ -138,7 +144,7 @@ fn from_fits_skymap_internal( String::from("starts with 'PROB'"), String::from(ttype1), ); - eprintln!("WARNING: {}", err); + warn!("{}", err); } let tform1 = check_keyword_and_get_str_val(it80.next().unwrap(), b"TFORM1 ")?; let (is_f64, n_pack) = if tform1 == "D" || tform1 == "1D" { @@ -168,7 +174,10 @@ fn from_fits_skymap_internal( if let Some(previous_mkw) = moc_kws.insert(mkw?) { // A FITS keyword MUST BE uniq (I may be more relax here, taking the last one and not complaining) // return Err(FitsError::MultipleKeyword(previous_mkw.keyword_str().to_string())) - eprintln!("WARNING: Keyword '{}' found more than once in a same HDU! We use the first occurrence.", previous_mkw.keyword_str()); + warn!( + "Keyword '{}' found more than once in a same HDU! We use the first occurrence.", + previous_mkw.keyword_str() + ); moc_kws.insert(previous_mkw); } // else keyword added without error @@ -183,7 +192,7 @@ fn from_fits_skymap_internal( moc_kws.check_pixtype()?; // moc_kws.check_ordering(Ordering::Nested)?; if let Err(e) = moc_kws.check_coordsys() { - eprintln!("WARNING: {}", e); + warn!("{}", e); } moc_kws.check_index_schema(IndexSchema::Implicit)?; // - get MOC depth