<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>CCfits: Selecting Table Data</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.1 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> </ul> </div> </div> <div class="contents"> <h1><a class="anchor" id="filter">Selecting Table Data </a></h1><p>This function demonstrates the operation of filtering a table by selecting rows that satisfy a condition and writing them to a new file, or overwriting a table with the filtered data. A third mode, where a filtered dataset is appended to the file containing the source data, will be available shortly, but is currently not supported by cfitsio.</p> <p>The expression syntax for the conditions that may be applied to table data are described in the <a href="http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html">cfitsio manual.</a> In the example below, we illustrate filtering with a boolean expression involving one of the columns.</p> <p>The two flags at the end of the call to FITS::filter are an `overwrite' flag - which only has meaning if the inFile and outFile are the same, and a 'read' flag. overwrite defaults to true. The second flag is a 'read' flag which defaults to false. When set true the user has immediate access to the filtered data.</p> <p>(Also see the section "Reading with Extended File Name Syntax")</p> <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> selectRows() { <span class="keyword">const</span> <span class="keywordtype">string</span> inFile(<span class="stringliteral">"atestfil.fit"</span>); <span class="keyword">const</span> <span class="keywordtype">string</span> outFile(<span class="stringliteral">"btestfil.fit"</span>); <span class="keyword">const</span> <span class="keywordtype">string</span> newFile(<span class="stringliteral">"ctestfil.fit"</span>); <span class="keyword">remove</span>(newFile.c_str()); <span class="comment">// test 1: write to a new file</span> std::auto_ptr<FITS> pInfile(<span class="keyword">new</span> FITS(inFile,Write,<span class="keywordtype">string</span>(<span class="stringliteral">"PLANETS_ASCII"</span>))); FITS* infile(pInfile.get()); std::auto_ptr<FITS> pNewfile(<span class="keyword">new</span> FITS(newFile,Write)); ExtHDU& source = infile->extension(<span class="stringliteral">"PLANETS_ASCII"</span>); <span class="keyword">const</span> <span class="keywordtype">string</span> expression(<span class="stringliteral">"DENSITY > 3.0"</span>); Table& sink1 = pNewfile->filter(expression,source,<span class="keyword">false</span>,<span class="keyword">true</span>); std::cout << sink1 << std::endl; <span class="comment">// test 2: write a new HDU to the current file, overwrite false, read true.</span> <span class="comment">// AS OF 7/2/01 does not work because of a bug in cfitsio, but does not</span> <span class="comment">// crash, simply writes a new header to the file without also writing the</span> <span class="comment">// selected data.</span> Table& sink2 = infile->filter(expression,source,<span class="keyword">false</span>,<span class="keyword">true</span>); std::cout << sink2 << std::endl; <span class="comment">// reset the source file back to the extension in question.</span> source = infile->extension(<span class="stringliteral">"PLANETS_ASCII"</span>); <span class="comment">// test 3: overwrite the current HDU with filtered data.</span> Table& sink3 = infile->filter(expression,source,<span class="keyword">true</span>,<span class="keyword">true</span>); std::cout << sink3 << std::endl; <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr size="1"/><address style="text-align: right;"><small>Generated on Wed Sep 9 11:59:41 2009 for CCfits by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address> </body> </html>