2020-07-24 10:38:13 +02:00
|
|
|
/*
|
|
|
|
* FLOATIMG
|
|
|
|
* import/export to/from FITS files
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <fitsio.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
extern int verbosity;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int fimg_save_R_as_fits(FloatImg *src, char *outname, int flags)
|
|
|
|
{
|
|
|
|
fitsfile *fptr; /* pointer to the FITS file */
|
2020-07-24 14:23:02 +02:00
|
|
|
int status, idx, k, sz;
|
2020-07-24 10:38:13 +02:00
|
|
|
int bitpix = FLOAT_IMG;
|
|
|
|
|
|
|
|
long naxis = 2;
|
|
|
|
long naxes[2];
|
|
|
|
float **array;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outname, flags);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
|
|
|
|
remove(outname); /* Delete old file if it already exists */
|
|
|
|
if (fits_create_file(&fptr, outname, &status)) {
|
|
|
|
fits_report_error(stderr, status);
|
|
|
|
return -9;
|
|
|
|
}
|
|
|
|
|
|
|
|
naxes[0] = src->width; naxes[1] = src->height;
|
|
|
|
|
|
|
|
array = calloc(src->height, sizeof(float *));
|
|
|
|
|
|
|
|
if (verbosity) fimg_describe(src, "to be saved as fits");
|
|
|
|
|
|
|
|
/* initialize pointers to the start of each row of the image */
|
|
|
|
for( idx=0; idx<naxes[1]; idx++ ) {
|
|
|
|
/**** MAGIC CODE MUST COME HERE ****/
|
2020-07-24 14:23:02 +02:00
|
|
|
k = naxes[1] - idx - 1;
|
|
|
|
array[idx] = src->R + (k*naxes[0]);
|
|
|
|
fprintf(stderr, " %6d %6d %p\n", idx, k, array[idx]);
|
2020-07-24 10:38:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( fits_create_img(fptr, bitpix, naxis, naxes, &status) ) {
|
|
|
|
fits_report_error(stderr, status);
|
|
|
|
return -10;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = naxes[0]*naxes[1];
|
|
|
|
if ( fits_write_img(fptr, TFLOAT, 1, sz, array[0], &status) ) {
|
|
|
|
fits_report_error(stderr, status);
|
|
|
|
return -10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( fits_close_file(fptr, &status) ) {
|
|
|
|
fits_report_error(stderr, status);
|
|
|
|
return -9;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|