Sophie

Sophie

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

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: Getting Started</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="cookbook">Getting Started </a></h1><p>The program cookbook.cxx, analogous to the cookbook.c program supplied with cfitsio, was generated to test the correct functioning of the parts of the library and to provide a demonstration of its usage.</p>
<p>The code for cookbook is reproduced here with commentary as worked example of the usage of the library.</p>
<h2><a class="anchor" id="main">
Driver Program</a></h2>
<div class="fragment"><pre class="fragment"><span class="comment">// The CCfits headers are expected to be installed in a subdirectory of</span>
<span class="comment">// the include path.</span>

<span class="comment">// The &lt;CCfits&gt; header file contains all that is necessary to use both the CCfits</span>
<span class="comment">// library and the cfitsio library (for example, it includes fitsio.h) thus making</span>
<span class="comment">// all of cfitsio&apos;s macro definitions available.</span>

<span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<span class="preprocessor"></span><span class="preprocessor">#include &quot;config.h&quot;</span>
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="comment">// this includes 12 of the CCfits headers and will support all CCfits operations.</span>
<span class="comment">// the installed location of the library headers is $(ROOT)/include/CCfits</span>

<span class="comment">// to use the library either add -I$(ROOT)/include/CCfits or #include &lt;CCfits/CCfits&gt;</span>
<span class="comment">// in the compilation target.</span>

<span class="preprocessor">#include &lt;CCfits&gt;</span>

<span class="preprocessor">#include &lt;cmath&gt;</span>
    <span class="comment">// The library is enclosed in a namespace.</span>
        
    <span class="keyword">using namespace </span>CCfits;




<span class="keywordtype">int</span> main();
<span class="keywordtype">int</span> writeImage();
<span class="keywordtype">int</span> writeAscii();
<span class="keywordtype">int</span> writeBinary();
<span class="keywordtype">int</span> copyHDU();
<span class="keywordtype">int</span> selectRows();
<span class="keywordtype">int</span> readHeader(); 
<span class="keywordtype">int</span> readImage();
<span class="keywordtype">int</span> readTable();
<span class="keywordtype">int</span> readExtendedSyntax();

<span class="keywordtype">int</span> main()
{


     FITS::setVerboseMode(<span class="keyword">true</span>);

     <span class="keywordflow">try</span>
                     
     {

        <span class="keywordflow">if</span> (!writeImage()) std::cerr &lt;&lt; <span class="stringliteral">&quot; writeImage() \n&quot;</span>;
        <span class="keywordflow">if</span> (!writeAscii()) std::cerr &lt;&lt; <span class="stringliteral">&quot; writeAscii() \n&quot;</span>;
        <span class="keywordflow">if</span> (!writeBinary()) std::cerr &lt;&lt; <span class="stringliteral">&quot; writeBinary()  \n&quot;</span>;
        <span class="keywordflow">if</span> (!copyHDU()) std::cerr &lt;&lt; <span class="stringliteral">&quot; copyHDU() \n&quot;</span>;
        <span class="keywordflow">if</span> (!readHeader()) std::cerr &lt;&lt; <span class="stringliteral">&quot; readHeader() \n&quot;</span>;
        <span class="keywordflow">if</span> (!readImage()) std::cerr &lt;&lt; <span class="stringliteral">&quot; readImage() \n&quot;</span>;
        <span class="keywordflow">if</span> (!readTable()) std::cerr &lt;&lt; <span class="stringliteral">&quot; readTable() \n&quot;</span>;
        <span class="keywordflow">if</span> (!readExtendedSyntax()) std::cerr &lt;&lt; <span class="stringliteral">&quot; readExtendedSyntax() \n&quot;</span>;
        <span class="keywordflow">if</span> (!selectRows()) std::cerr &lt;&lt; <span class="stringliteral">&quot; selectRows() \n&quot;</span>;

     }
     <span class="keywordflow">catch</span> (FitsException&amp;) 
     <span class="comment">// will catch all exceptions thrown by CCfits, including errors</span>
     <span class="comment">// found by cfitsio (status != 0)</span>
     {
             
        std::cerr &lt;&lt; <span class="stringliteral">&quot; Fits Exception Thrown by test function \n&quot;</span>;       
             
     }
    <span class="keywordflow">return</span> 0;
}
</pre></div><p> The simple driver program illustrates the setting of verbose mode for the library, which makes all internal exceptions visible to the programmer. This is primarily for debugging purposes; exceptions are in some cases used to transfer control in common circumstances (e.g. testing whether a file should be created or appended to in write operations). Most of the exceptions will not produce a message unless this flag is set.</p>
<p>Nearly all of the exceptions thrown by CCfits are derived from FitsException, which is caught by reference in the above example. This includes all nonzero status codes returned by cfitsio by the following construct (recall that in the <a href="http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html">cfitsio library</a> nearly all functions return a non-zero status code on error, and have a final argument status of type int):</p>
<div class="fragment"><pre class="fragment"> <span class="keywordflow">if</span> ( [cfitsio call](args,...,&amp;status)) <span class="keywordflow">throw</span> FitsError(status);
</pre></div><p>FitsError, derived from FitsException, uses a cfitsio library call to convert the status code to a string message.</p>
<p>The few exceptions that are not derived from FitsException indicate fatal conditions implying bugs in the library. These print a message suggesting the user contact <a href="mailto:&#120;&#097;&#110;&#112;&#114;&#111;&#098;&#064;&#097;&#116;&#104;&#101;&#110;&#097;&#046;&#103;&#115;&#102;&#099;&#046;&#110;&#097;&#115;&#097;&#046;&#103;&#111;&#118;">HEASARC</a> to report the problem.</p>
<p>Note also the lack of statements for closing files in any of the following routines, The destructor (dtor) for the FITS object does this when it falls out of scope. A call</p>
<p>FITS::destroy() throw()</p>
<p>is provided for closing files explicitly; destroy() is also responsible for cleaning up the FITS object and deallocating its resources.</p>
<p>When the data are being read instead of written, the user is expected to copy the data into other program variables [rather than use references to the data contained in the FITS object].</p>
<p>The routines in this program test the following functionality:</p>
<p>writeImage() <a class="el" href="writeimage.html">Writing Primary Images and Image Extensions</a></p>
<p>writeAscii() <a class="el" href="ascii.html">Creating and Writing to an Ascii Table Extension</a></p>
<p>writeBinary() <a class="el" href="binary.html">Creating and Writing to a Binary Table Extension</a></p>
<p>copyHDU() <a class="el" href="copy.html">Copying an Extension between Files</a></p>
<p>selectRows() <a class="el" href="filter.html">Selecting Table Data</a></p>
<p>readHeader() <a class="el" href="readhead.html">Reading Header information from a HDU</a></p>
<p>readImage() <a class="el" href="readimage.html">Reading an Image</a></p>
<p>readTable() <a class="el" href="readtable.html">Reading a Table Extension</a></p>
<p>readExtendedSyntax() <a class="el" href="readextendedsyntax.html">Reading with Extended File Name Syntax</a> </p>
</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>