Skip to content

Commit

Permalink
Add vector type support (ex: '100E') and fix bit handling
Browse files Browse the repository at this point in the history
* Rows can be of vector type, where each row has multiple of the same data type in the column. Bitmasks (32X) and strings (20A) are the most common examples, but others exist in the wild.
* In more fully supporting repeats, revamped the bit handling.
* Filled out the data type support and added round-trip read-write tests for all vector types. Weirdly, I couldn't get the u32 case to work and suspect a CFITSIO bug. Then again, all unsigned types are unofficial CFITSIO extensions beyond the FITS spec.
* Removed conditionals for reads_col_impl and writes_col_impl; int is 32 bits and long long is consistently 64 bits on all machines and platforms. Only long is weird and special.
  • Loading branch information
fotonick committed Jul 20, 2024
1 parent 2c9aef3 commit 12231fc
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]
### Added
* Support for vector data-types in reading and writing tables.
### Changed
### Removed

Expand Down
10 changes: 6 additions & 4 deletions fitsio/src/fitsfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,27 +368,29 @@ impl FitsFile {
for i in 0..num_cols {
let mut name_buffer: Vec<libc::c_char> = vec![0; 71];
let mut type_buffer: Vec<libc::c_char> = vec![0; 71];
let mut repeats: libc::c_long = 0;
unsafe {
fits_get_bcolparms(
self.fptr.as_mut() as *mut _,
i + 1,
name_buffer.as_mut_ptr(),
ptr::null_mut(),
type_buffer.as_mut_ptr(),
ptr::null_mut(),
&mut repeats as *mut libc::c_long,
ptr::null_mut(),
ptr::null_mut(),
ptr::null_mut(),
ptr::null_mut(),
&mut status,
);
}

column_descriptions.push(ConcreteColumnDescription {
let mut col = ConcreteColumnDescription {
name: stringutils::buf_to_string(&name_buffer)?,
data_type: stringutils::buf_to_string(&type_buffer)?
.parse::<ColumnDataDescription>()?,
});
};
col.data_type.repeat = repeats as usize;
column_descriptions.push(col);
}

HduInfo::TableInfo {
Expand Down
4 changes: 2 additions & 2 deletions fitsio/src/hdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ impl FitsHdu {
# }
```
*/
pub fn write_col_range<T: WritesCol, N: Into<String>>(
pub fn write_col_range<T: WritesCol, N: Into<String> + Clone>(
&self,
fits_file: &mut FitsFile,
name: N,
Expand Down Expand Up @@ -807,7 +807,7 @@ impl FitsHdu {
# }
```
*/
pub fn write_col<T: WritesCol, N: Into<String>>(
pub fn write_col<T: WritesCol, N: Into<String> + Clone>(
&self,
fits_file: &mut FitsFile,
name: N,
Expand Down
70 changes: 63 additions & 7 deletions fitsio/src/longnam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#![allow(unused_imports, dead_code)]

pub(crate) use crate::sys::{
ffclos, ffcopy, ffcrim, ffcrtb, ffdcol, ffdhdu, ffflmd, ffgbcl, ffgcdw, ffgcno, ffgcvd, ffgcve,
ffgcvi, ffgcvj, ffgcvjj, ffgcvk, ffgcvs, ffgcvui, ffgcvuj, ffgcvujj, ffgcvuk, ffghdn, ffghdt,
ffgidm, ffgiet, ffgisz, ffgkyd, ffgkye, ffgkyj, ffgkyjj, ffgkyl, ffgkys, ffgncl, ffgnrw, ffgpv,
ffgsv, fficol, ffinit, ffmahd, ffmnhd, ffopen, ffpcl, ffpcls, ffphps, ffpky, ffpkyd, ffpkye,
ffpkys, ffppr, ffpss, ffrsim, ffthdu, fitsfile, LONGLONG,
ffclos, ffcopy, ffcrim, ffcrtb, ffdcol, ffdhdu, ffflmd, ffgbcl, ffgcdw, ffgcno, ffgcvb, ffgcvd,
ffgcve, ffgcvi, ffgcvj, ffgcvjj, ffgcvk, ffgcvs, ffgcvsb, ffgcvui, ffgcvuj, ffgcvujj, ffgcvuk,
ffgcx, ffghdn, ffghdt, ffgidm, ffgiet, ffgisz, ffgkyd, ffgkye, ffgkyj, ffgkyjj, ffgkyl, ffgkys,
ffgncl, ffgnrw, ffgpv, ffgsv, fficol, ffinit, ffmahd, ffmnhd, ffopen, ffpcl, ffpcls, ffpclx,
ffphps, ffpky, ffpkyd, ffpkye, ffpkys, ffppr, ffpss, ffrsim, ffthdu, fitsfile, LONGLONG,
};
pub use libc::{
c_char, c_double, c_float, c_int, c_long, c_short, c_uint, c_ulong, c_ulonglong, c_ushort,
c_void,
c_char, c_double, c_float, c_int, c_long, c_schar, c_short, c_uchar, c_uint, c_ulong,
c_ulonglong, c_ushort, c_void,
};

pub(crate) unsafe fn fits_close_file(fptr: *mut fitsfile, status: *mut libc::c_int) -> c_int {
Expand Down Expand Up @@ -132,6 +132,50 @@ pub(crate) unsafe fn fits_read_col_str(
)
}

pub(crate) unsafe fn fits_read_col_bit(
fptr: *mut fitsfile,
colnum: c_int,
firstrow: LONGLONG,
firstbit: LONGLONG,
nbits: LONGLONG,
larray: *mut c_char,
status: *mut c_int,
) -> c_int {
ffgcx(fptr, colnum, firstrow, firstbit, nbits, larray, status)
}

pub(crate) unsafe fn fits_read_col_byt(
fptr: *mut fitsfile,
colnum: c_int,
firstrow: LONGLONG,
firstelem: LONGLONG,
nelem: LONGLONG,
nulval: c_uchar,
array: *mut c_uchar,
anynul: *mut c_int,
status: *mut c_int,
) -> c_int {
ffgcvb(
fptr, colnum, firstrow, firstelem, nelem, nulval, array, anynul, status,
)
}

pub(crate) unsafe fn fits_read_col_sbyt(
fptr: *mut fitsfile,
colnum: c_int,
firstrow: LONGLONG,
firstelem: LONGLONG,
nelem: LONGLONG,
nulval: c_schar,
array: *mut c_schar,
anynul: *mut c_int,
status: *mut c_int,
) -> c_int {
ffgcvsb(
fptr, colnum, firstrow, firstelem, nelem, nulval, array, anynul, status,
)
}

pub(crate) unsafe fn fits_read_col_sht(
fptr: *mut fitsfile,
colnum: c_int,
Expand Down Expand Up @@ -489,6 +533,18 @@ pub(crate) unsafe fn fits_write_col(
)
}

pub(crate) unsafe fn fits_write_col_bit(
fptr: *mut fitsfile,
colnum: c_int,
firstrow: LONGLONG,
firstbit: c_long,
nbit: c_long,
larray: *mut c_char,
status: *mut c_int,
) -> c_int {
ffpclx(fptr, colnum, firstrow, firstbit, nbit, larray, status)
}

pub(crate) unsafe fn fits_write_col_str(
fptr: *mut fitsfile,
colnum: c_int,
Expand Down
Loading

0 comments on commit 12231fc

Please sign in to comment.