Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用CFITSIO库从FITS表读取可变长度数组_C++_C_Fits - Fatal编程技术网

C++ 使用CFITSIO库从FITS表读取可变长度数组

C++ 使用CFITSIO库从FITS表读取可变长度数组,c++,c,fits,C++,C,Fits,我很难使用CFITSIO库从FITS表的条目中读取可变长度数组(由于我正在开发的另一个软件,我不得不使用它们) 现在,我试图阅读的FITS表如下所示: 如您所见,最后三列的单元格中没有标量值,而是包含可变长度数组 对于这种特殊情况,CFITSIO文档没有太大帮助:大多数基本例程被认为是通过直接读取正则列(单元格中有标量,请参见第2节)来生成数组。 fits\u read\u col不适用于此数据结构 现在,在读取变量列时,建议使用fits\u read\u descript例程。问题在于,此函

我很难使用CFITSIO库从FITS表的条目中读取可变长度数组(由于我正在开发的另一个软件,我不得不使用它们)

现在,我试图阅读的FITS表如下所示:

如您所见,最后三列的单元格中没有标量值,而是包含可变长度数组

对于这种特殊情况,
CFITSIO
文档没有太大帮助:大多数基本例程被认为是通过直接读取正则列(单元格中有标量,请参见第2节)来生成数组。
fits\u read\u col
不适用于此数据结构

现在,在读取变量列时,建议使用
fits\u read\u descript
例程。问题在于,此函数返回低级信息,特别是存储数组的堆中的起始偏移量(请参阅的第7节)。 因此,即使我获得了关于包含多个数组的单元格的低级信息,也不清楚如何使用它来获取数值

这些方法的帮助不大,而且没有这样复杂的数据结构的例子

以前有人这样做过吗?是否有人能够使用
CFITSIO
读取可变长度数组来生成代码片段?这将非常有帮助

可以找到我截图的FITS文件

这里是一个尝试性的片段,打开文件并检查列和行,对可变长度列应用建议的
fits\u read\u descript
函数。我不知道如何继续,因为我不知道如何利用返回的参数来获取表中的实际数值

#include "fitsio.h"
#include <iostream>

int main(){

    fitsfile *fp = 0; // pointer to fitsfile type provided in CFITSIO library
    int status = 0; // variable passed down to different CFITSIO functions 

    // open the fits file, go to the Header Data Unit 1 containing the table 
    // with variable-length arrays
    fits_open_file(&fp, "rmf_obs5029747.fits[1]", READONLY, &status);

    // read HDU type
    int hdutype;
    fits_get_hdu_type(fp, &hdutype, &status);
    std::cout << "found type " << hdutype << " HDU type." << "\n";

    // read number of rows and columns
    long nTableRows;
    int  nTableCols;
    fits_get_num_rows(fp, &nTableRows, &status);
    fits_get_num_cols(fp, &nTableCols, &status);
    std::cout << "the table has " << nTableRows << " rows" << "\n";
    std::cout << "the table has " << nTableCols << " columns" << "\n";

    // loop through the columns and consider only those with a negative typecode
    // indicating that they contain a variable-length array
    // https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node29.html
    int typecode;
    long repeat;
    long width; 
    long offset;

    for (int colnum = 0; colnum < nTableCols; ++colnum) {
        fits_get_coltype(fp, colnum+1, &typecode, &repeat, &width, &status);
        if (typecode < 1) {
            std::cout << "->column " << colnum << " contains a variable-length array" << "\n"; 
            std::cout << "->examining its rows..." << "\n";
            // loop through the rows
            for (int rownum = 0; rownum < nTableRows; ++rownum)
                fits_read_descript(fp, colnum, rownum, &repeat, &offset, &status);
        }
    }
}
#包括“fitsio.h”
#包括
int main(){
fitsfile*fp=0;//指向CFITSIO库中提供的fitsfile类型的指针
int status=0;//传递给不同CFITSIO函数的变量
//打开fits文件,转到包含表格的标题数据单元1
//使用可变长度数组
fits_open_文件(&fp,“rmf_obs5029747.fits[1]”,只读,&status);
//读取HDU类型
int-hdutype;
适合获取hdu类型(fp、hdu类型和状态);

std::cout只是一个想法,也许你已经看到了/想到了这个,但以防万一,如果你没有看到的话

拟合\u get\u col\u display\u width()=以了解可用字符数


如果fits\u read\u descript()给出数组中的元素数和起始偏移量,那么总字节数是否可以读入字符串并用分隔符“,”进行标记并获得数字?

fits中有许多奇怪的特殊情况,您已经找到了其中之一

我已经成功地使用了这个

  • 调用
    fits\u read\u descript{s}{ll}()
    确定相关行的重复和偏移量。还可以使用
    descripts
    变量一次确定多行的重复和偏移量
  • 调用
    fits\u read\u col{null}()
    读取数据,一次读取一行。元素的数量是从步骤1中找到的重复计数,如果需要子集,则可以减少重复计数。像通常一样设置列、行号和第一个元素。使用
    null
    变量可以很好地工作
  • 重要的是,这种方式一次只能读取一行可变长度数据,但它省去了执行所有字节解码和堆索引的麻烦。即使使用
    fits\u read\u descripts()
    variant来确定一个函数调用中的多个重复计数,也必须调用fits\u read\u col()对于您感兴趣的每个表行,一次


    读取可变长度字符串或位数组本身就是一种有趣的消遣,但您看起来只是想读取X射线响应矩阵数据(浮点),所以这应该可以回答您的问题。

    感谢@lorenz和@CraigM的建议

    我实际上找到了解决方案并在中实现了它,因此如果其他人有相同的问题,可以复制解决方案或直接使用ROOT。 我介绍的读取根中可变长度单元格的函数是:

    我是一年前做的,但忘了在这里贴答案:)

    您可以通过解决方案找到代码


    实际上,我使用了你在@CraigM提出的方案,即将
    fits\u read\u descrippt
    fits\u read\u col

    Hi@lorenz,谢谢你的帮助。
    fits\u get\u col\u display\u width()
    用于可变长度列时崩溃。但你是对的
    fits\u read\u descrippt(fitsfile*fptr,int colnum,LONGLONG rownum,>long*repeat,long*offset,int*status)
    返回元素数
    repeat
    和起始
    offset
    。只是我不知道如何使用它们…有一个
    适合读取字节(fitsfile*fptr、LONGLONG firstrow、LONGLONG firstchar、LONGLONG nchars、>unsigned char*值、int*状态)
    但文档不清楚
    firstrow
    firstchar
    nchars
    是什么。