Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > ecbd8c5b7568e331fe6ea5b9a07a78a0 > files > 142

CCfits-docs-2.2-2.fc13.noarch.rpm

<!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&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;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">&quot;atestfil.fit&quot;</span>);
         <span class="keyword">const</span> <span class="keywordtype">string</span> outFile(<span class="stringliteral">&quot;btestfil.fit&quot;</span>);
         <span class="keyword">const</span> <span class="keywordtype">string</span> newFile(<span class="stringliteral">&quot;ctestfil.fit&quot;</span>);
         <span class="keyword">remove</span>(newFile.c_str());
       
         <span class="comment">// test 1: write to a new file</span>
         std::auto_ptr&lt;FITS&gt; pInfile(<span class="keyword">new</span> FITS(inFile,Write,<span class="keywordtype">string</span>(<span class="stringliteral">&quot;PLANETS_ASCII&quot;</span>)));
         FITS* infile(pInfile.get());
         std::auto_ptr&lt;FITS&gt; pNewfile(<span class="keyword">new</span> FITS(newFile,Write));
         ExtHDU&amp; source = infile-&gt;extension(<span class="stringliteral">&quot;PLANETS_ASCII&quot;</span>);
         <span class="keyword">const</span> <span class="keywordtype">string</span> expression(<span class="stringliteral">&quot;DENSITY &gt; 3.0&quot;</span>);
         
         
         Table&amp; sink1 = pNewfile-&gt;filter(expression,source,<span class="keyword">false</span>,<span class="keyword">true</span>);

                
         std::cout &lt;&lt; sink1 &lt;&lt; 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&amp; sink2 = infile-&gt;filter(expression,source,<span class="keyword">false</span>,<span class="keyword">true</span>);
         
         std::cout &lt;&lt; sink2 &lt;&lt; std::endl;
         
         <span class="comment">// reset the source file back to the extension in question.</span>
         source = infile-&gt;extension(<span class="stringliteral">&quot;PLANETS_ASCII&quot;</span>);
          
         <span class="comment">// test 3: overwrite the current HDU with filtered data.</span>
                    
         Table&amp; sink3 = infile-&gt;filter(expression,source,<span class="keyword">true</span>,<span class="keyword">true</span>);
         
         std::cout &lt;&lt; sink3 &lt;&lt; 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&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>