使用CFITSIO访问C中的大型fits网格的正确方法是什么

使用CFITSIO访问C中的大型fits网格的正确方法是什么,c,fits,C,Fits,我使用CFITSIO()访问两个拟合网格。现在,第一个网格是1071(row)x3(cols),属于浮点数据类型。我可以访问此页面并打印每个条目的输出。当我为我的第二个网格(一个大网格(1.1 Gb))重复这段代码时,它是1071 x 262144,也是浮点数据类型,我得到了一个分段错误。在我继续之前,下面是代码: #FILE Cspec.c #include <stdio.h> #include <stdlib.h> #include <math.h> #i

我使用CFITSIO()访问两个拟合网格。现在,第一个网格是1071(row)x3(cols),属于浮点数据类型。我可以访问此页面并打印每个条目的输出。当我为我的第二个网格(一个大网格(1.1 Gb))重复这段代码时,它是1071 x 262144,也是浮点数据类型,我得到了一个分段错误。在我继续之前,下面是代码:

#FILE Cspec.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "fitsio.h"
#include "load_data.h"
#include "general_functions.h"


#define MAX_ROW 230746
#define N 131072
#define WAVEMIN 450.0
#define WAVEMAX 650.0


void printerror( int status)
{
/*****************************************************/
/* Print out cfitsio error messages and exit program */
/*****************************************************/


if (status)
{
   fits_report_error(stderr, status); /* print error report */

   exit( status );   
}
return;
}



int main()
{   /*----------------------------
    Now load the table
----------------------------*/
printf("\n\n--------------------\nLoading the models..\n--------------------");
fflush(stdout);

// Imports and definitions
fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */
int status, anynull;
long naxes[2], fpixel, nbuffer, npixels, ii;
char filename[]  = "models.fits";     /* name of existing FITS file   */
status = 0;

// Open the file and kick off if its not there
if ( fits_open_file(&fptr, filename, READONLY, &status) )
    printerror( status );

/* read the NAXIS1 and NAXIS2 keyword to get image size */
//if ( fits_read_keys_lng(fptr, "NAXIS", 1, 2, naxes, &nfound, &status) )
//      printerror( status );

// Define the rows and columns of fits image and thus the buffer size
naxes[0] = 1017;
naxes[1] = 262144;
    size_t buffsize = ((size_t) (naxes[1] * naxes[0]) + (naxes[1] * sizeof(float)));
float nullval, buffer[buffsize];
npixels  = naxes[0] * naxes[1];         /* number of pixels in the image */
fpixel   = 1;
nullval  = 0;                /* don't check for null values in the image */

while (npixels > 0)
{
    nbuffer = npixels;
    if (npixels > buffsize)
    nbuffer = buffsize;     /* read as many pixels as will fit in buffer */

    if ( fits_read_img(fptr, TFLOAT, fpixel, nbuffer, &nullval,
      buffer, &anynull, &status) )
    printerror( status );

    for (ii = 0; ii < nbuffer; ii++)  
    {
        // Output the value
        printf("%f\t", buffer[ii]);
    }
    npixels -= nbuffer;    /* increment remaining number of pixels */
    fpixel  += nbuffer;    /* next pixel to be read in image */
}

if ( fits_close_file(fptr, &status) )
    printerror( status );

return 0;
}
其他c文件(general_functions.c和load_data.c)不相关。最后两个标志的原因来自于描述使用fits文件时的大小限制。这说明了一点(第4段):

"如果在支持大文件的平台上使用-D_LARGEFILE_SOURCE和-D_FILE_OFFSET_BITS=64标志编译CFITSIO,则它可以读取和写入包含多达2**31 2880字节FITS记录或大约6 TB大小的FITS文件。仍然要求每个扩展名中NAXISn和PCOUNT关键字的值在有符号4字节整数的范围(最大值=2147483648)。因此,图像的每个维度(由NAXISn关键字给出)、表的总宽度(NAXIS1关键字)、表中的行数(NAXIS2关键字)以及二进制表中可变长度数组堆的总大小(PCOUNT关键字)必须小于此限制。”

我假设添加这些标志会解决这个问题,因为1071*262144=280756224低于有符号4字节整数(最大值=2147483648)的范围。这里还有更多信息()。我哪里出错了?为什么这会导致seg故障?此代码适用于较小的网格(1071*3)。我假设我必须添加一些额外的编译器标志或更改代码中的某些内容?问题可能在于我使用的是来自IRAF发行版的cfitsio吗

我从调试中发现的一件事是,我无法输出“buffsize”变量——这本身就导致了seg故障

我正在运行64位Ubuntu16.04 LTS,我正在使用nvcc编译器,因为我计划将一些后续工作卸载到GPU上。我对C(来自python)还是比较陌生的

谢谢

萨姆

nvcc Cspec2.c general_functions.c load_data.c -I/iraf/iraf/vendor/cfitsio  /iraf/iraf/vendor/cfitsio/libcfitsio.a  -lm -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64