less code, less bug ?

This commit is contained in:
Tonton Th 2020-07-25 04:26:06 +02:00
parent 421dd724a7
commit c6dee909e8

View File

@ -1,6 +1,9 @@
/*
* FLOATIMG
* import/export to/from FITS files
https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node1.html
*/
#include <stdio.h>
@ -21,7 +24,7 @@ int bitpix = FLOAT_IMG;
long naxis = 2;
long naxes[2];
float **array;
// XXX float *array[1];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outname, flags);
@ -36,22 +39,23 @@ if (fits_create_file(&fptr, outname, &status)) {
}
naxes[0] = src->width; naxes[1] = src->height;
array = calloc(src->height, sizeof(float *));
// XXX array = calloc(src->height, sizeof(float *));
if (verbosity) fimg_describe(src, "to be saved as FITS");
#define REVERSE 1
/* initialize pointers to the start of each row of the image */
/************************************************************
***** MAGIC CODE MUST COME HERE ?
array[0] = src->R;
#define REVERSE 1
for( idx=0; idx<naxes[1]; idx++ ) {
/**** MAGIC CODE MUST COME HERE ****/
#if REVERSE
k = naxes[1] - idx - 1;
#else
k = idx;
#endif
array[idx] = src->R + (k*naxes[0]);
fprintf(stderr, " %6d %6d %p\n", idx, k, array[idx]);
fprintf(stderr, " %6d %6d %p\n", idx, k, array[idx]);
}
**************************************************************/
if ( fits_create_img(fptr, bitpix, naxis, naxes, &status) ) {
fits_report_error(stderr, status);
@ -59,7 +63,7 @@ if ( fits_create_img(fptr, bitpix, naxis, naxes, &status) ) {
}
sz = naxes[0]*naxes[1];
if ( fits_write_img(fptr, TFLOAT, 1, sz, array[0], &status) ) {
if ( fits_write_img(fptr, TFLOAT, 1, sz, src->R, &status) ) {
fits_report_error(stderr, status);
return -10;
}