Example #1
0
File: img.c Project: rforge/rfitsio
/* Wrapper to fits_create_img and fits_create_imgll */
SEXP
cfitsio_create_img (SEXP fits_object,
		    SEXP bits_per_pixel,
		    SEXP naxes)
{
    fits_file_t * fits = R_ExternalPtrAddr (fits_object);

    if (NULL != fits && NULL != fits->cfitsio_ptr)
    {
	int i;
	int num_of_dimensions;
	LONGLONG * axes_dimensions;

	num_of_dimensions = length (naxes);
	axes_dimensions = (LONGLONG *) R_alloc (sizeof (LONGLONG),
						num_of_dimensions);
	for (i = 0; i < num_of_dimensions; ++i)
	    axes_dimensions[i] = (LONGLONG) (REAL(naxes)[i]);

	fits_create_imgll (fits->cfitsio_ptr,
			   INTEGER(bits_per_pixel)[0],
			   num_of_dimensions,
			   axes_dimensions,
			   &(fits->status));
    }

    return R_NilValue;
}
Example #2
0
static int
vips_fits_set_header( VipsFits *fits, VipsImage *in )
{
	int status;
	int bitpix;
	int i;

	status = 0;

	fits->naxis = 3;
	fits->naxes[0] = in->Xsize;
	fits->naxes[1] = in->Ysize;
	fits->naxes[2] = in->Bands;

	for( i = 0; i < VIPS_NUMBER( fits2vips_formats ); i++ )
		if( fits2vips_formats[i][1] == in->BandFmt )
			break;
	if( i == VIPS_NUMBER( fits2vips_formats ) ) {
		vips_error( "fits", 
			_( "unsupported BandFmt %d\n" ), in->BandFmt );
		return( -1 );
	}
	bitpix = fits2vips_formats[i][0];
	fits->datatype = fits2vips_formats[i][2];

#ifdef VIPS_DEBUG
	VIPS_DEBUG_MSG( "naxis = %d\n", fits->naxis );
	for( i = 0; i < fits->naxis; i++ )
		VIPS_DEBUG_MSG( "%d) %lld\n", i, fits->naxes[i] );
	VIPS_DEBUG_MSG( "bitpix = %d\n", bitpix );
#endif /*VIPS_DEBUG*/

	if( fits_create_imgll( fits->fptr, bitpix, fits->naxis, 
		fits->naxes, &status ) ) {
		vips_fits_error( status );
		return( -1 );
	}

	if( vips_image_map( in,
		(VipsImageMapFn) vips_fits_write_meta, fits ) )
		return( -1 );

	return( 0 );
}