#include <stdio.h>
#include "pslib.h"

#define NAME "test.fits"
#define SIZE 128

int main(int argc, char *argv[])
{
    // Make two images
    psImage *image1 = psImageAlloc(SIZE, SIZE, PS_TYPE_F32);
    psImage *image2 = psImageAlloc(SIZE, SIZE, PS_TYPE_F32);
    for (int i = 0; i < SIZE; i++) {
	for (int j = 0; j < SIZE; j++) {
	    image1->data.F32[i][j] = +1.0;
	    image2->data.F32[i][j] = -1.0;
	}
    }

    // Write out the first one
    psFits *fitsFile1 = psFitsAlloc(NAME);
    if (!psFitsWriteImage(fitsFile1, NULL, image1, 0, NULL)) {
	psErrorStackPrint(stderr, "Unable to write image: %s\n", NAME);
    }
    psFree(fitsFile1);

    // Write out the second one
    psFits *fitsFile2 = psFitsAlloc(NAME); // We "accidentally" on purpose give it the same name
    if (!psFitsWriteImage(fitsFile2, NULL, image2, 0, NULL)) {
	psErrorStackPrint(stderr, "Unable to write image: %s\n", NAME);
    }
    psFree(fitsFile2);
 
    printf("Done.\n");
}
