0
我正在嘗試使用cfitsio
編寫並使用像素數據將圖像填充到新的適合文件中。我不確定我在做什麼錯誤,但所有數據都沒有寫入到適合文件中。我用binary vi
檢查數據和圖像數據沒有正確創建。我使用NASA website的第二個image HST WFPC 2 fits file。這是我寫的代碼:將像素數據寫入FITS文件Cfitsio
#include <string.h>
#include <stdio.h>
#include "fitsio.h"
int main() {
fitsfile *fptr;
int status = 0, i;
fits_open_file(&fptr, "WFPC2ASSNu5780205bx.fits", READONLY, &status);
long naxes[2];
fits_get_img_size(fptr, 3, naxes, &status);
fitsfile *ofptr;
fits_create_file(&ofptr, "o_nasa.fits", &status);
fits_copy_header(fptr, ofptr, &status);
long fp[2] = {1, 1};
long nelements = naxes[0];
float arr[nelements];
for (i = 0; i < nelements; i++) {
arr[i] = 100;
}
int ii, jj, kk;
for (ii = 1; ii <= naxes[0]; ii++) {
for (jj = 1; jj <= naxes[1]; jj++) {
fits_write_pix(ofptr, TFLOAT, fp, nelements, arr, &status); // this is not working
}
}
fits_close_file(ofptr, &status);
fits_close_file(fptr, &status);
return status;
}