CCfits 2.7

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

Reading with Extended File Name Syntax

It is also possible to apply extended file name syntax (as described in chapter 10 of the cfitsio manual) when reading data. The function below shows a typical example using the basic CCfits::FITS constructor.

The extended syntax is entered as part of the file name string. In this case it specifies an HDU and a row selection criterion dependent upon the values in the column named "Density." Any read operations performed on this HDU will only see rows which meet the "Density > 5.2" condition. Also the current header position in the file is automatically placed at the specified HDU upon construction of the FITS object.

Extended file name syntax can also be used with the FITS constructors which take specific HDU names or indices as arguments. However if the extended syntax specifies an HDU, that HDU must also be among those specified as a FITS constructor argument, otherwise a CCfits::FITS::OperationNotSupported exception is thrown. For example:

    FITS fits(new FITS("myFile.fit[HDU_A]",Read,string("HDU_A"))); // OK
    FITS fits(new FITS("myFile.fit[HDU_B]",Read,string("HDU_A"))); // Error

(Note - The extended file name feature which allows the opening of a particular image located in the row of a table remains unsupported in CCfits.)

    int readExtendedSyntax()
    {
        // Current extension will be set to PLANETS_ASCII after construction:
        std::auto_ptr<FITS> pInfile(new FITS("btestfil.fit[PLANETS_ASCII][Density > 5.2]"));
        std::cout << "\nCurrent extension: "
                  << pInfile->currentExtensionName() << std::endl;

        Column& col = pInfile->currentExtension().column("Density");
        std::vector<double> densities;

        // nRows should only include rows with density column vals > 5.2.
        const int nRows = col.rows();
        col.read(densities, 1, nRows);
        for (int i=0; i<nRows; ++i)
           std::cout << densities[i] << "  ";
        std::cout << std::endl;

        return 0;
    }