51 cpl_propertylist * header )
53 int psize = cpl_propertylist_get_size( header ) ;
58 for ( ip = 0 ; ip < psize ; ip++ ) {
59 const cpl_property * pcur ;
65 pcur = cpl_propertylist_get( header, ip ) ;
66 type = cpl_property_get_type( pcur ) ;
67 name = (
char *)cpl_property_get_name( pcur ) ;
68 if ( strncmp( name,
"NAXIS", 5 ) == 0 || strcmp( name,
"SIMPLE" ) == 0 ||
69 strcmp( name,
"BSCALE" ) == 0 || strcmp( name,
"BZERO" ) == 0 ||
70 strcmp( name,
"EXTEND" ) == 0 || strcmp( name,
"BITPIX" ) == 0 )
72 comment = (
char *)cpl_property_get_comment( pcur ) ;
79 s[0] = cpl_property_get_char( pcur ) ;
81 fits_write_key_str( fptr, name,
s, comment, &fio_status ) ;
82 if ( fio_status != 0 ) {
83 xsh_msg(
"fits_write_key_str ERROR %d", fio_status ) ;
89 int b = cpl_property_get_bool( pcur ) ;
90 int value = b == TRUE ? 1 : 0 ;
91 fits_write_key_log( fptr, name, value, comment, &fio_status ) ;
92 if ( fio_status != 0 ) {
93 xsh_msg(
"fits_write_key Bool ERROR %d", fio_status ) ;
99 int value = cpl_property_get_int(pcur);
101 fits_write_key_lng(fptr, name, value, comment, &fio_status);
102 if ( fio_status != 0 ) {
103 xsh_msg(
"fits_write_key INT ERROR %d", fio_status ) ;
109 long value = cpl_property_get_long(pcur);
111 fits_write_key_lng(fptr, name, value, comment, &fio_status);
112 if ( fio_status != 0 ) {
113 xsh_msg(
"fits_write_key LONG ERROR %d", fio_status ) ;
120 float value = cpl_property_get_float(pcur);
122 fits_write_key_flt(fptr, name, value, -8, comment, &fio_status);
123 if ( fio_status != 0 ) {
124 xsh_msg(
"fits_write_key FLOAT ERROR %d", fio_status ) ;
128 case CPL_TYPE_DOUBLE:
130 double value = cpl_property_get_double(pcur);
132 fits_write_key_dbl(fptr, name, value, -9, comment, &fio_status);
133 if ( fio_status != 0 ) {
134 xsh_msg(
"fits_write_key DOUBLE ERROR %d", fio_status ) ;
139 case CPL_TYPE_STRING:
141 char *value = (
char *)cpl_property_get_string(pcur);
143 if (strcmp(name,
"COMMENT") == 0) {
144 if(strcmp(value,
"") == 0){
145 fits_write_comment(fptr,
" ", &fio_status);
146 if ( fio_status != 0 ) {
147 xsh_msg(
"fits_write_comment ERROR %d", fio_status ) ;
151 fits_write_comment(fptr, value, &fio_status);
152 if ( fio_status != 0 ) {
153 xsh_msg(
"fits_write_comment ERROR %d", fio_status ) ;
157 else if(strcmp(name,
"HISTORY") == 0) {
158 if(strcmp(value,
"") == 0){
159 fits_write_history(fptr,
" ", &fio_status);
160 if ( fio_status != 0 ) {
161 xsh_msg(
"fits_write_history ERROR %d", fio_status ) ;
165 fits_write_history(fptr, value, &fio_status);
166 if ( fio_status != 0 ) {
167 xsh_msg(
"fits_write_history ERROR %d", fio_status ) ;
172 fits_write_key_str(fptr, name, value, comment, &fio_status);
173 if ( fio_status != 0 ) {
174 xsh_msg(
"fits_write_key_str ERROR %d", fio_status ) ;
204 int nelements, elem_size ;
211 nelements =
nx *
ny * nz ;
212 elem_size = cpl_type_get_sizeof( type ) ;
214 nelements, elem_size, type ) ;
216 check( result->
pixels = cpl_calloc( nelements, elem_size ) ) ;
221 result->
type = type ;
239 int img_size,
nx,
ny ;
240 int img_3d_nx, img_3d_ny, img_3d_nz ;
241 cpl_type img_type, img_3d_type ;
242 cpl_error_code err = CPL_ERROR_NONE ;
257 check( img_type = cpl_image_get_type( img ) ) ;
258 check(
nx = cpl_image_get_size_x( img ) ) ;
259 check(
ny = cpl_image_get_size_y( img ) ) ;
270 elem_size = cpl_type_get_sizeof( img_type ) ;
272 elem_size, img_type ) ;
274 if ( elem_size == 0 ) {
275 err = CPL_ERROR_INVALID_TYPE ;
279 p_pix += iz*img_size*elem_size ;
280 memcpy( p_pix, cpl_image_get_data( img ), img_size*elem_size ) ;
283 if ( err != CPL_ERROR_NONE ) {
295 char *extname = NULL;
300 int nbpixels, nullval = 0, anynull ;
307 if (xtnum == 0) extname = cpl_sprintf(
"%s", filename) ;
308 else extname = cpl_sprintf(
"%s[%d]", filename, xtnum) ;
310 ffopen(&fptr, extname, READONLY, &fio_status) ;
314 fits_get_img_dim(fptr, &naxis, &fio_status) ;
320 fits_get_img_size(fptr, naxis, naxes, &fio_status) ;
323 naxis, naxes[0], naxes[1], naxes[2] ) ;
327 result->
nx = naxes[0] ;
328 result->
ny = naxes[1] ;
329 result->
nz = naxes[2] ;
330 nbpixels = result->
nx * result->
ny * result->
nz ;
342 case CPL_TYPE_DOUBLE:
344 fits_type = TDOUBLE ;
352 fits_read_img( fptr, fits_type, 1, nbpixels, &nullval, result->
pixels,
353 &anynull, &fio_status ) ;
356 fits_close_file( fptr, &fio_status ) ;
378 cpl_propertylist * header,
381 cpl_type_bpp bpp_loc ;
394 switch( img_3d->
type ) {
396 bpp_loc = CPL_BPP_32_SIGNED ;
400 bpp_loc = CPL_BPP_IEEE_FLOAT ;
403 case CPL_TYPE_DOUBLE:
404 bpp_loc = CPL_BPP_IEEE_DOUBLE ;
405 fits_type = TDOUBLE ;
408 bpp_loc = CPL_BPP_32_SIGNED ;
415 size = naxes[0]*naxes[1]*naxes[2] ;
417 if (
mode == CPL_IO_DEFAULT ) {
420 if ( access( fname, 0 ) == 0 ) {
424 fits_create_file( &fptr, fname, &fio_status ) ;
430 ffopen( &fptr, fname, READWRITE, &fio_status ) ;
435 fits_create_img( fptr, bpp_loc, 3, naxes, &fio_status);
439 fits_write_img( fptr, fits_type, 1,
size, img_3d->
pixels, &fio_status ) ;
444 if ( header != NULL )
447 fits_close_file( fptr, &fio_status ) ;
452 return cpl_error_get_code() ;
491 void * result = NULL ;
502 cpl_type result = 0 ;
505 result = img_3d->
type ;
514 if ( img_3d != NULL && *img_3d != NULL ) {
void * xsh_image_3d_get_data(xsh_image_3d *img_3d)
cpl_error_code xsh_image_3d_insert(xsh_image_3d *img_3d, cpl_image *img, int iz)
static void xsh_image_3d_write_fits_header(fitsfile *fptr, cpl_propertylist *header)
int xsh_image_3d_get_size_x(xsh_image_3d *img_3d)
int xsh_image_3d_get_size_y(xsh_image_3d *img_3d)
int xsh_image_3d_get_size_z(xsh_image_3d *img_3d)
void xsh_image_3d_free(xsh_image_3d **img_3d)
cpl_error_code xsh_image_3d_save(xsh_image_3d *img_3d, const char *fname, cpl_propertylist *header, unsigned mode)
cpl_type xsh_image_3d_get_type(xsh_image_3d *img_3d)
xsh_image_3d * xsh_image_3d_new(int nx, int ny, int nz, cpl_type type)
xsh_image_3d * xsh_image_3d_load(const char *filename, cpl_type type, int xtnum)
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define XSH_ASSURE_NOT_NULL(pointer)
#define xsh_msg_dbg_medium(...)
#define xsh_msg_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
#define xsh_msg_dbg_high(...)
#define XSH_FREE(POINTER)
#define XSH_MALLOC(POINTER, TYPE, SIZE)
#define XSH_CALLOC(POINTER, TYPE, SIZE)