LALSample.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Jolien Creighton
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /************************************ <lalVerbatim file="LALSampleCV">
00021 Author: Creighton, T. D.
00022 $Id: LALSample.c,v 1.6 2007/06/08 14:41:52 bema Exp $
00023 ************************************* </lalVerbatim> */
00024 
00025 /********************************************************** <lalLaTeX>
00026 \subsection{Module \texttt{LALSample.c}}
00027 \label{ss:LALSample.c}
00028 
00029 Example module for LAL.
00030 
00031 \subsubsection*{Prototypes}
00032 \input{LALSampleCP}
00033 \idx{LALREAL8Invert()}
00034 \idx{LALREAL8Divide()}
00035 
00036 \subsubsection*{Description}
00037 
00038 This module exists to demostrate documentation and coding standards
00039 for LAL modules, using two trivial functions.  \verb@LALREAL8Invert()@
00040 computes \verb@*output@ = 1/\verb@input@; if \verb@input@ = 0, it
00041 leaves \verb@*output@ unchanged and returns an error.
00042 \verb@LALREAL8Divide()@ computes \verb@*output@ =
00043 \verb@numer@/\verb@denom@, calling \verb@LALREAL8Invert()@ as a
00044 subroutine.  This allows us to demonstrate LAL error handling through
00045 nested function calls.
00046 
00047 \subsubsection*{Algorithm}
00048 
00049 \subsubsection*{Uses}
00050 
00051 \subsubsection*{Notes}
00052 
00053 \vfill{\footnotesize\input{LALSampleCV}}
00054 
00055 ******************************************************* </lalLaTeX> */
00056 
00057 #include <lal/LALStdlib.h>
00058 #include <lal/LALSample.h>
00059 
00060 NRCSID( LALSAMPLEC, "$Id: LALSample.c,v 1.6 2007/06/08 14:41:52 bema Exp $" );
00061 
00062 /* <lalVerbatim file="LALSampleCP"> */
00063 void
00064 LALREAL8Invert( LALStatus *stat, REAL8 *output, REAL8 input )
00065 { /* </lalVerbatim> */
00066   INITSTATUS( stat, "LALREAL8Invert", LALSAMPLEC );
00067 
00068   /* This traps coding errors in the calling routine. */
00069   ASSERT( output != NULL, stat, LALSAMPLEH_ENULL, LALSAMPLEH_MSGENULL );
00070 
00071   /* This traps runtime errors. */
00072   if ( input == 0.0 )
00073   {
00074     ABORT( stat, LALSAMPLEH_EDIV0, LALSAMPLEH_MSGEDIV0 );
00075   }
00076 
00077   *output = 1.0/input;
00078   RETURN( stat );
00079 }
00080 
00081 
00082 /* <lalVerbatim file="LALSampleCP"> */
00083 void
00084 LALREAL8Divide( LALStatus *stat, REAL8 *output, REAL8 numer, REAL8 denom )
00085 { /* </lalVerbatim> */
00086   INITSTATUS( stat, "LALREAL8Divide", LALSAMPLEC );
00087   ATTATCHSTATUSPTR( stat );
00088 
00089   TRY( LALREAL8Invert( stat->statusPtr, output, denom ), stat );
00090   *output *= numer;
00091 
00092   DETATCHSTATUSPTR( stat );
00093   RETURN( stat );
00094 }

Generated on Tue Oct 14 02:32:01 2008 for LAL by  doxygen 1.5.2