VectorFactories.c

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------- 
00002 
00003 File Name: VectorFactories.c
00004 
00005 <lalVerbatim file="VectorFactoriesCV">
00006 Revision: $Id: VectorFactories.m4,v 1.5 2003/09/29 00:33:24 dwchin Exp $
00007 </lalVerbatim>
00008 
00009 -------------------------------------------------------------------------*/
00010 
00011 /* <lalLaTeX>
00012 
00013 \subsection{Module \texttt{VectorFactories.c}}
00014 \label{ss:VectorFactories.c}
00015 
00016 Create/destroy $\langle\mbox{datatype}\rangle$Vector objects. 
00017 
00018 \subsubsection*{Prototypes}
00019 \vspace{0.1in}
00020 \input{VectorFactoriesD}
00021 \idx{LALZCreateVector()}
00022 \idx{LALCCreateVector()}
00023 \idx{LALDCreateVector()}
00024 \idx{LALSCreateVector()}
00025 \idx{LALI2CreateVector()}
00026 \idx{LALI4CreateVector()}
00027 \idx{LALI8CreateVector()}
00028 \idx{LALU2CreateVector()}
00029 \idx{LALU4CreateVector()}
00030 \idx{LALU8CreateVector()}
00031 \idx{LALCHARCreateVector()}
00032 \idx{LALCreateVector()}
00033 \idx{LALZDestroyVector()}
00034 \idx{LALCDestroyVector()}
00035 \idx{LALDDestroyVector()}
00036 \idx{LALSDestroyVector()}
00037 \idx{LALI2DestroyVector()}
00038 \idx{LALI4DestroyVector()}
00039 \idx{LALI8DestroyVector()}
00040 \idx{LALU2DestroyVector()}
00041 \idx{LALU4DestroyVector()}
00042 \idx{LALU8DestroyVector()}
00043 \idx{LALCHARDestroyVector()}
00044 \idx{LALDestroyVector()}
00045 
00046 \subsubsection*{Description}
00047 
00048 The \texttt{CreateVector} family of functions create a
00049 $\langle\mbox{datatype}\rangle$\texttt{Vector} of the appropriate
00050 dimensions.
00051 
00052 The \texttt{ResizeVector} family of functions changes the amount of
00053 storage allocated by the \texttt{CreateVector} functions.
00054 
00055 The \texttt{DestroyVector} family of functions return the storage allocated by
00056 the \texttt{CreateVector} functions to the system.
00057 
00058 \subsubsection*{Algorithm}
00059 
00060 \subsubsection*{Uses}
00061 \begin{verbatim}
00062 LALMalloc()
00063 LALFree()
00064 \end{verbatim}
00065 
00066 \subsubsection*{Notes}
00067 
00068 \vfill{\footnotesize\input{VectorFactoriesCV}}
00069 
00070 </lalLaTeX> */
00071 
00072 #include "LALStdlib.h"
00073 #include "AVFactories.h"
00074 
00075 /* <lalVerbatim file="VectorFactoriesNRCSID"> */
00076 NRCSID( VECTORFACTORIESC, "$Id: VectorFactories.m4,v 1.5 2003/09/29 00:33:24 dwchin Exp $" );
00077 /* </lalVerbatim> */
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094  
00095 
00096 COMPLEX16Vector * XLALCreateCOMPLEX16Vector ( UINT4 length )
00097 {
00098   COMPLEX16Vector * vector;
00099   vector = LALMalloc( sizeof( *vector ) );
00100   if ( ! vector )
00101     XLAL_ERROR_NULL( "XLALCreateCOMPLEX16Vector", XLAL_ENOMEM );
00102   vector->length = length;
00103   if ( ! length ) /* zero length: set data pointer to be NULL */
00104     vector->data = NULL;
00105   else /* non-zero length: allocate memory for data */
00106   {
00107     vector->data = LALMalloc( length * sizeof( *vector->data ) );
00108     if ( ! vector->data )
00109     {
00110       LALFree( vector );
00111       XLAL_ERROR_NULL( "XLALCreateCOMPLEX16Vector", XLAL_ENOMEM );
00112     }
00113   }
00114   return vector;
00115 }
00116 
00117 /* <lalVerbatim file="VectorFactoriesD"> */
00118 void LALZCreateVector ( LALStatus *status, COMPLEX16Vector **vector, UINT4 length ) 
00119 { /* </lalVerbatim> */
00120   /* 
00121    * Initialize status structure
00122    */
00123 
00124   INITSTATUS( status, "LALZCreateVector", VECTORFACTORIESC );   
00125       
00126   /* Check sequence length: report error if 0 
00127    * Use of unsigned for length means we can't check if negative
00128    * length was passed
00129    */
00130 
00131   ASSERT( length > 0, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00132 
00133   /* 
00134    * Check return structure: If return pointer does not point to a
00135    *    valid pointer then report an error 
00136    */
00137 
00138   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00139 
00140   ASSERT( *vector == NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00141 
00142   /*
00143    * Allocate pointer
00144    */
00145 
00146   *vector = XLALCreateCOMPLEX16Vector ( length );
00147   if ( ! *vector )
00148   {
00149     XLALClearErrno();
00150     ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00151   }
00152 
00153   /* We be done: Normal exit */
00154 
00155   RETURN( status );
00156 }
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172  
00173 
00174 
00175 
00176 COMPLEX16Vector * XLALResizeCOMPLEX16Vector ( COMPLEX16Vector * vector, UINT4 length )
00177 {
00178   if ( ! vector )
00179     return XLALCreateCOMPLEX16Vector ( length );
00180   if ( ! length )
00181   {
00182     XLALDestroyCOMPLEX16Vector ( vector );
00183     return NULL;
00184   }
00185   vector->data = LALRealloc( vector->data, length * sizeof( *vector->data ) );
00186   if ( ! vector->data )
00187   {
00188     vector->length = 0;
00189     XLAL_ERROR_NULL( "XLALResizeCOMPLEX16Vector", XLAL_ENOMEM );
00190   }
00191   vector->length = length;
00192   return vector;
00193 }
00194 
00195 
00196 /* <lalVerbatim file="VectorFactoriesD"> */
00197 void LALZResizeVector ( LALStatus *status, COMPLEX16Vector **vector, UINT4 length ) 
00198 { /* </lalVerbatim> */
00199   /* 
00200    * Initialize status structure
00201    */
00202   INITSTATUS( status, "LALZResizeVector", VECTORFACTORIESC );   
00203 
00204   ASSERT ( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00205   ASSERT ( ! *vector || (*vector)->length, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00206   ASSERT ( length || *vector, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00207 
00208   /* Want this to behave like realloc(3), i.e.
00209    * *vector == NULL => create a new vector 
00210    * length == 0 => destroy the vector 
00211    * otherwise => resize given vector 
00212    */
00213 
00214   *vector = XLALResizeCOMPLEX16Vector ( *vector, length );
00215   if ( xlalErrno )
00216   {
00217     int code = xlalErrno;
00218     XLALClearErrno(); 
00219     if ( code == XLAL_EBADLEN )
00220     {
00221       ABORT( status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00222     }
00223     if ( code == XLAL_ENOMEM )
00224     {
00225       ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00226     }
00227   }
00228       
00229   RETURN( status );
00230 }
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246  
00247 
00248 void XLALDestroyCOMPLEX16Vector ( COMPLEX16Vector *vector )
00249 {
00250   if ( ! vector )
00251     return;
00252   if ( ( ! vector->length || ! vector->data ) && ( vector->length || vector->data  ) )
00253     XLAL_ERROR_VOID( "XLALDestroyCOMPLEX16Vector", XLAL_EINVAL );
00254   if ( vector->data )
00255     LALFree( vector->data );
00256   vector->data = NULL; /* leave length non-zero to detect repeated frees */
00257   LALFree( vector );
00258   return;
00259 }
00260 
00261 /* <lalVerbatim file="VectorFactoriesD"> */
00262 void LALZDestroyVector ( LALStatus *status, COMPLEX16Vector **vector )
00263 { /* </lalVerbatim> */
00264   /* 
00265    * Initialize status
00266    */
00267 
00268   INITSTATUS( status, "LALZDestroyVector", VECTORFACTORIESC );  
00269       
00270   /* 
00271    * Check vector: is it non-NULL?
00272    */
00273 
00274   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00275 
00276   /* 
00277    * Check vector: does it point to non-NULL?
00278    */
00279 
00280   ASSERT( *vector != NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00281 
00282   /*
00283    * Check data in vector: does it point to non-NULL
00284    */
00285 
00286   ASSERT( (*vector)->data != NULL, status,
00287           AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
00288 
00289   /* Ok, now let's free allocated storage */
00290 
00291   XLALDestroyCOMPLEX16Vector ( *vector );
00292   if ( xlalErrno )
00293   {
00294     int code = xlalErrno;
00295     XLALClearErrno();
00296     if ( code == XLAL_EFAULT )
00297     {
00298       ABORT( status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00299     }
00300     if ( code == XLAL_EINVAL )
00301     {
00302       ABORT( status, AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
00303     }
00304   }
00305 
00306   *vector = NULL;               /* make sure we don't point to freed struct */
00307 
00308   RETURN( status );
00309 }
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 
00323 
00324 
00325 
00326 
00327  
00328 
00329 COMPLEX8Vector * XLALCreateCOMPLEX8Vector ( UINT4 length )
00330 {
00331   COMPLEX8Vector * vector;
00332   vector = LALMalloc( sizeof( *vector ) );
00333   if ( ! vector )
00334     XLAL_ERROR_NULL( "XLALCreateCOMPLEX8Vector", XLAL_ENOMEM );
00335   vector->length = length;
00336   if ( ! length ) /* zero length: set data pointer to be NULL */
00337     vector->data = NULL;
00338   else /* non-zero length: allocate memory for data */
00339   {
00340     vector->data = LALMalloc( length * sizeof( *vector->data ) );
00341     if ( ! vector->data )
00342     {
00343       LALFree( vector );
00344       XLAL_ERROR_NULL( "XLALCreateCOMPLEX8Vector", XLAL_ENOMEM );
00345     }
00346   }
00347   return vector;
00348 }
00349 
00350 /* <lalVerbatim file="VectorFactoriesD"> */
00351 void LALCCreateVector ( LALStatus *status, COMPLEX8Vector **vector, UINT4 length ) 
00352 { /* </lalVerbatim> */
00353   /* 
00354    * Initialize status structure
00355    */
00356 
00357   INITSTATUS( status, "LALCCreateVector", VECTORFACTORIESC );   
00358       
00359   /* Check sequence length: report error if 0 
00360    * Use of unsigned for length means we can't check if negative
00361    * length was passed
00362    */
00363 
00364   ASSERT( length > 0, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00365 
00366   /* 
00367    * Check return structure: If return pointer does not point to a
00368    *    valid pointer then report an error 
00369    */
00370 
00371   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00372 
00373   ASSERT( *vector == NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00374 
00375   /*
00376    * Allocate pointer
00377    */
00378 
00379   *vector = XLALCreateCOMPLEX8Vector ( length );
00380   if ( ! *vector )
00381   {
00382     XLALClearErrno();
00383     ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00384   }
00385 
00386   /* We be done: Normal exit */
00387 
00388   RETURN( status );
00389 }
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
00401 
00402 
00403 
00404 
00405  
00406 
00407 
00408 
00409 COMPLEX8Vector * XLALResizeCOMPLEX8Vector ( COMPLEX8Vector * vector, UINT4 length )
00410 {
00411   if ( ! vector )
00412     return XLALCreateCOMPLEX8Vector ( length );
00413   if ( ! length )
00414   {
00415     XLALDestroyCOMPLEX8Vector ( vector );
00416     return NULL;
00417   }
00418   vector->data = LALRealloc( vector->data, length * sizeof( *vector->data ) );
00419   if ( ! vector->data )
00420   {
00421     vector->length = 0;
00422     XLAL_ERROR_NULL( "XLALResizeCOMPLEX8Vector", XLAL_ENOMEM );
00423   }
00424   vector->length = length;
00425   return vector;
00426 }
00427 
00428 
00429 /* <lalVerbatim file="VectorFactoriesD"> */
00430 void LALCResizeVector ( LALStatus *status, COMPLEX8Vector **vector, UINT4 length ) 
00431 { /* </lalVerbatim> */
00432   /* 
00433    * Initialize status structure
00434    */
00435   INITSTATUS( status, "LALCResizeVector", VECTORFACTORIESC );   
00436 
00437   ASSERT ( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00438   ASSERT ( ! *vector || (*vector)->length, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00439   ASSERT ( length || *vector, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00440 
00441   /* Want this to behave like realloc(3), i.e.
00442    * *vector == NULL => create a new vector 
00443    * length == 0 => destroy the vector 
00444    * otherwise => resize given vector 
00445    */
00446 
00447   *vector = XLALResizeCOMPLEX8Vector ( *vector, length );
00448   if ( xlalErrno )
00449   {
00450     int code = xlalErrno;
00451     XLALClearErrno(); 
00452     if ( code == XLAL_EBADLEN )
00453     {
00454       ABORT( status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00455     }
00456     if ( code == XLAL_ENOMEM )
00457     {
00458       ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00459     }
00460   }
00461       
00462   RETURN( status );
00463 }
00464 
00465 
00466 
00467 
00468 
00469 
00470 
00471 
00472 
00473 
00474 
00475 
00476 
00477 
00478 
00479  
00480 
00481 void XLALDestroyCOMPLEX8Vector ( COMPLEX8Vector *vector )
00482 {
00483   if ( ! vector )
00484     return;
00485   if ( ( ! vector->length || ! vector->data ) && ( vector->length || vector->data  ) )
00486     XLAL_ERROR_VOID( "XLALDestroyCOMPLEX8Vector", XLAL_EINVAL );
00487   if ( vector->data )
00488     LALFree( vector->data );
00489   vector->data = NULL; /* leave length non-zero to detect repeated frees */
00490   LALFree( vector );
00491   return;
00492 }
00493 
00494 /* <lalVerbatim file="VectorFactoriesD"> */
00495 void LALCDestroyVector ( LALStatus *status, COMPLEX8Vector **vector )
00496 { /* </lalVerbatim> */
00497   /* 
00498    * Initialize status
00499    */
00500 
00501   INITSTATUS( status, "LALCDestroyVector", VECTORFACTORIESC );  
00502       
00503   /* 
00504    * Check vector: is it non-NULL?
00505    */
00506 
00507   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00508 
00509   /* 
00510    * Check vector: does it point to non-NULL?
00511    */
00512 
00513   ASSERT( *vector != NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00514 
00515   /*
00516    * Check data in vector: does it point to non-NULL
00517    */
00518 
00519   ASSERT( (*vector)->data != NULL, status,
00520           AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
00521 
00522   /* Ok, now let's free allocated storage */
00523 
00524   XLALDestroyCOMPLEX8Vector ( *vector );
00525   if ( xlalErrno )
00526   {
00527     int code = xlalErrno;
00528     XLALClearErrno();
00529     if ( code == XLAL_EFAULT )
00530     {
00531       ABORT( status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00532     }
00533     if ( code == XLAL_EINVAL )
00534     {
00535       ABORT( status, AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
00536     }
00537   }
00538 
00539   *vector = NULL;               /* make sure we don't point to freed struct */
00540 
00541   RETURN( status );
00542 }
00543 
00544 
00545 
00546 
00547 
00548 
00549 
00550 
00551 
00552 
00553 
00554 
00555 
00556 
00557 
00558 
00559 
00560  
00561 
00562 REAL8Vector * XLALCreateREAL8Vector ( UINT4 length )
00563 {
00564   REAL8Vector * vector;
00565   vector = LALMalloc( sizeof( *vector ) );
00566   if ( ! vector )
00567     XLAL_ERROR_NULL( "XLALCreateREAL8Vector", XLAL_ENOMEM );
00568   vector->length = length;
00569   if ( ! length ) /* zero length: set data pointer to be NULL */
00570     vector->data = NULL;
00571   else /* non-zero length: allocate memory for data */
00572   {
00573     vector->data = LALMalloc( length * sizeof( *vector->data ) );
00574     if ( ! vector->data )
00575     {
00576       LALFree( vector );
00577       XLAL_ERROR_NULL( "XLALCreateREAL8Vector", XLAL_ENOMEM );
00578     }
00579   }
00580   return vector;
00581 }
00582 
00583 /* <lalVerbatim file="VectorFactoriesD"> */
00584 void LALDCreateVector ( LALStatus *status, REAL8Vector **vector, UINT4 length ) 
00585 { /* </lalVerbatim> */
00586   /* 
00587    * Initialize status structure
00588    */
00589 
00590   INITSTATUS( status, "LALDCreateVector", VECTORFACTORIESC );   
00591       
00592   /* Check sequence length: report error if 0 
00593    * Use of unsigned for length means we can't check if negative
00594    * length was passed
00595    */
00596 
00597   ASSERT( length > 0, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00598 
00599   /* 
00600    * Check return structure: If return pointer does not point to a
00601    *    valid pointer then report an error 
00602    */
00603 
00604   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00605 
00606   ASSERT( *vector == NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00607 
00608   /*
00609    * Allocate pointer
00610    */
00611 
00612   *vector = XLALCreateREAL8Vector ( length );
00613   if ( ! *vector )
00614   {
00615     XLALClearErrno();
00616     ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00617   }
00618 
00619   /* We be done: Normal exit */
00620 
00621   RETURN( status );
00622 }
00623 
00624 
00625 
00626 
00627 
00628 
00629 
00630 
00631 
00632 
00633 
00634 
00635 
00636 
00637 
00638  
00639 
00640 
00641 
00642 REAL8Vector * XLALResizeREAL8Vector ( REAL8Vector * vector, UINT4 length )
00643 {
00644   if ( ! vector )
00645     return XLALCreateREAL8Vector ( length );
00646   if ( ! length )
00647   {
00648     XLALDestroyREAL8Vector ( vector );
00649     return NULL;
00650   }
00651   vector->data = LALRealloc( vector->data, length * sizeof( *vector->data ) );
00652   if ( ! vector->data )
00653   {
00654     vector->length = 0;
00655     XLAL_ERROR_NULL( "XLALResizeREAL8Vector", XLAL_ENOMEM );
00656   }
00657   vector->length = length;
00658   return vector;
00659 }
00660 
00661 
00662 /* <lalVerbatim file="VectorFactoriesD"> */
00663 void LALDResizeVector ( LALStatus *status, REAL8Vector **vector, UINT4 length ) 
00664 { /* </lalVerbatim> */
00665   /* 
00666    * Initialize status structure
00667    */
00668   INITSTATUS( status, "LALDResizeVector", VECTORFACTORIESC );   
00669 
00670   ASSERT ( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00671   ASSERT ( ! *vector || (*vector)->length, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00672   ASSERT ( length || *vector, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00673 
00674   /* Want this to behave like realloc(3), i.e.
00675    * *vector == NULL => create a new vector 
00676    * length == 0 => destroy the vector 
00677    * otherwise => resize given vector 
00678    */
00679 
00680   *vector = XLALResizeREAL8Vector ( *vector, length );
00681   if ( xlalErrno )
00682   {
00683     int code = xlalErrno;
00684     XLALClearErrno(); 
00685     if ( code == XLAL_EBADLEN )
00686     {
00687       ABORT( status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00688     }
00689     if ( code == XLAL_ENOMEM )
00690     {
00691       ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00692     }
00693   }
00694       
00695   RETURN( status );
00696 }
00697 
00698 
00699 
00700 
00701 
00702 
00703 
00704 
00705 
00706 
00707 
00708 
00709 
00710 
00711 
00712  
00713 
00714 void XLALDestroyREAL8Vector ( REAL8Vector *vector )
00715 {
00716   if ( ! vector )
00717     return;
00718   if ( ( ! vector->length || ! vector->data ) && ( vector->length || vector->data  ) )
00719     XLAL_ERROR_VOID( "XLALDestroyREAL8Vector", XLAL_EINVAL );
00720   if ( vector->data )
00721     LALFree( vector->data );
00722   vector->data = NULL; /* leave length non-zero to detect repeated frees */
00723   LALFree( vector );
00724   return;
00725 }
00726 
00727 /* <lalVerbatim file="VectorFactoriesD"> */
00728 void LALDDestroyVector ( LALStatus *status, REAL8Vector **vector )
00729 { /* </lalVerbatim> */
00730   /* 
00731    * Initialize status
00732    */
00733 
00734   INITSTATUS( status, "LALDDestroyVector", VECTORFACTORIESC );  
00735       
00736   /* 
00737    * Check vector: is it non-NULL?
00738    */
00739 
00740   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00741 
00742   /* 
00743    * Check vector: does it point to non-NULL?
00744    */
00745 
00746   ASSERT( *vector != NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00747 
00748   /*
00749    * Check data in vector: does it point to non-NULL
00750    */
00751 
00752   ASSERT( (*vector)->data != NULL, status,
00753           AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
00754 
00755   /* Ok, now let's free allocated storage */
00756 
00757   XLALDestroyREAL8Vector ( *vector );
00758   if ( xlalErrno )
00759   {
00760     int code = xlalErrno;
00761     XLALClearErrno();
00762     if ( code == XLAL_EFAULT )
00763     {
00764       ABORT( status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00765     }
00766     if ( code == XLAL_EINVAL )
00767     {
00768       ABORT( status, AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
00769     }
00770   }
00771 
00772   *vector = NULL;               /* make sure we don't point to freed struct */
00773 
00774   RETURN( status );
00775 }
00776 
00777 
00778 
00779 
00780 
00781 
00782 
00783 
00784 
00785 
00786 
00787 
00788 
00789 
00790 
00791 
00792 
00793  
00794 
00795 REAL4Vector * XLALCreateREAL4Vector ( UINT4 length )
00796 {
00797   REAL4Vector * vector;
00798   vector = LALMalloc( sizeof( *vector ) );
00799   if ( ! vector )
00800     XLAL_ERROR_NULL( "XLALCreateREAL4Vector", XLAL_ENOMEM );
00801   vector->length = length;
00802   if ( ! length ) /* zero length: set data pointer to be NULL */
00803     vector->data = NULL;
00804   else /* non-zero length: allocate memory for data */
00805   {
00806     vector->data = LALMalloc( length * sizeof( *vector->data ) );
00807     if ( ! vector->data )
00808     {
00809       LALFree( vector );
00810       XLAL_ERROR_NULL( "XLALCreateREAL4Vector", XLAL_ENOMEM );
00811     }
00812   }
00813   return vector;
00814 }
00815 
00816 /* <lalVerbatim file="VectorFactoriesD"> */
00817 void LALSCreateVector ( LALStatus *status, REAL4Vector **vector, UINT4 length ) 
00818 { /* </lalVerbatim> */
00819   /* 
00820    * Initialize status structure
00821    */
00822 
00823   INITSTATUS( status, "LALSCreateVector", VECTORFACTORIESC );   
00824       
00825   /* Check sequence length: report error if 0 
00826    * Use of unsigned for length means we can't check if negative
00827    * length was passed
00828    */
00829 
00830   ASSERT( length > 0, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00831 
00832   /* 
00833    * Check return structure: If return pointer does not point to a
00834    *    valid pointer then report an error 
00835    */
00836 
00837   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00838 
00839   ASSERT( *vector == NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00840 
00841   /*
00842    * Allocate pointer
00843    */
00844 
00845   *vector = XLALCreateREAL4Vector ( length );
00846   if ( ! *vector )
00847   {
00848     XLALClearErrno();
00849     ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00850   }
00851 
00852   /* We be done: Normal exit */
00853 
00854   RETURN( status );
00855 }
00856 
00857 
00858 
00859 
00860 
00861 
00862 
00863 
00864 
00865 
00866 
00867 
00868 
00869 
00870 
00871  
00872 
00873 
00874 
00875 REAL4Vector * XLALResizeREAL4Vector ( REAL4Vector * vector, UINT4 length )
00876 {
00877   if ( ! vector )
00878     return XLALCreateREAL4Vector ( length );
00879   if ( ! length )
00880   {
00881     XLALDestroyREAL4Vector ( vector );
00882     return NULL;
00883   }
00884   vector->data = LALRealloc( vector->data, length * sizeof( *vector->data ) );
00885   if ( ! vector->data )
00886   {
00887     vector->length = 0;
00888     XLAL_ERROR_NULL( "XLALResizeREAL4Vector", XLAL_ENOMEM );
00889   }
00890   vector->length = length;
00891   return vector;
00892 }
00893 
00894 
00895 /* <lalVerbatim file="VectorFactoriesD"> */
00896 void LALSResizeVector ( LALStatus *status, REAL4Vector **vector, UINT4 length ) 
00897 { /* </lalVerbatim> */
00898   /* 
00899    * Initialize status structure
00900    */
00901   INITSTATUS( status, "LALSResizeVector", VECTORFACTORIESC );   
00902 
00903   ASSERT ( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00904   ASSERT ( ! *vector || (*vector)->length, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00905   ASSERT ( length || *vector, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00906 
00907   /* Want this to behave like realloc(3), i.e.
00908    * *vector == NULL => create a new vector 
00909    * length == 0 => destroy the vector 
00910    * otherwise => resize given vector 
00911    */
00912 
00913   *vector = XLALResizeREAL4Vector ( *vector, length );
00914   if ( xlalErrno )
00915   {
00916     int code = xlalErrno;
00917     XLALClearErrno(); 
00918     if ( code == XLAL_EBADLEN )
00919     {
00920       ABORT( status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
00921     }
00922     if ( code == XLAL_ENOMEM )
00923     {
00924       ABORT( status, AVFACTORIESH_EMALLOC, AVFACTORIESH_MSGEMALLOC );
00925     }
00926   }
00927       
00928   RETURN( status );
00929 }
00930 
00931 
00932 
00933 
00934 
00935 
00936 
00937 
00938 
00939 
00940 
00941 
00942 
00943 
00944 
00945  
00946 
00947 void XLALDestroyREAL4Vector ( REAL4Vector *vector )
00948 {
00949   if ( ! vector )
00950     return;
00951   if ( ( ! vector->length || ! vector->data ) && ( vector->length || vector->data  ) )
00952     XLAL_ERROR_VOID( "XLALDestroyREAL4Vector", XLAL_EINVAL );
00953   if ( vector->data )
00954     LALFree( vector->data );
00955   vector->data = NULL; /* leave length non-zero to detect repeated frees */
00956   LALFree( vector );
00957   return;
00958 }
00959 
00960 /* <lalVerbatim file="VectorFactoriesD"> */
00961 void LALSDestroyVector ( LALStatus *status, REAL4Vector **vector )
00962 { /* </lalVerbatim> */
00963   /* 
00964    * Initialize status
00965    */
00966 
00967   INITSTATUS( status, "LALSDestroyVector", VECTORFACTORIESC );  
00968       
00969   /* 
00970    * Check vector: is it non-NULL?
00971    */
00972 
00973   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
00974 
00975   /* 
00976    * Check vector: does it point to non-NULL?
00977    */
00978 
00979   ASSERT( *vector != NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00980 
00981   /*
00982    * Check data in vector: does it point to non-NULL
00983    */
00984 
00985   ASSERT( (*vector)->data != NULL, status,
00986           AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
00987 
00988   /* Ok, now let's free allocated storage */
00989 
00990   XLALDestroyREAL4Vector ( *vector );
00991   if ( xlalErrno )
00992   {
00993     int code = xlalErrno;
00994     XLALClearErrno();
00995     if ( code == XLAL_EFAULT )
00996     {
00997       ABORT( status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
00998     }
00999     if ( code == XLAL_EINVAL )
01000     {
01001       ABORT( status, AVFACTORIESH_EDPTR, AVFACTORIESH_MSGEDPTR );
01002     }
01003   }
01004 
01005   *vector = NULL;               /* make sure we don't point to freed struct */
01006 
01007   RETURN( status );
01008 }
01009 
01010 
01011 
01012 
01013 
01014 
01015 
01016 
01017 
01018 
01019 
01020 
01021 
01022 
01023 
01024 
01025 
01026  
01027 
01028 INT2Vector * XLALCreateINT2Vector ( UINT4 length )
01029 {
01030   INT2Vector * vector;
01031   vector = LALMalloc( sizeof( *vector ) );
01032   if ( ! vector )
01033     XLAL_ERROR_NULL( "XLALCreateINT2Vector", XLAL_ENOMEM );
01034   vector->length = length;
01035   if ( ! length ) /* zero length: set data pointer to be NULL */
01036     vector->data = NULL;
01037   else /* non-zero length: allocate memory for data */
01038   {
01039     vector->data = LALMalloc( length * sizeof( *vector->data ) );
01040     if ( ! vector->data )
01041     {
01042       LALFree( vector );
01043       XLAL_ERROR_NULL( "XLALCreateINT2Vector", XLAL_ENOMEM );
01044     }
01045   }
01046   return vector;
01047 }
01048 
01049 /* <lalVerbatim file="VectorFactoriesD"> */
01050 void LALI2CreateVector ( LALStatus *status, INT2Vector **vector, UINT4 length ) 
01051 { /* </lalVerbatim> */
01052   /* 
01053    * Initialize status structure
01054    */
01055 
01056   INITSTATUS( status, "LALI2CreateVector", VECTORFACTORIESC );  
01057       
01058   /* Check sequence length: report error if 0 
01059    * Use of unsigned for length means we can't check if negative
01060    * length was passed
01061    */
01062 
01063   ASSERT( length > 0, status, AVFACTORIESH_ELENGTH, AVFACTORIESH_MSGELENGTH );
01064 
01065   /* 
01066    * Check return structure: If return pointer does not point to a
01067    *    valid pointer then report an error 
01068    */
01069 
01070   ASSERT( vector != NULL, status, AVFACTORIESH_EVPTR, AVFACTORIESH_MSGEVPTR );
01071 
01072   ASSERT( *vector == NULL, status, AVFACTORIESH_EUPTR, AVFACTORIESH_MSGEUPTR );
01073 
01074   /*
01075    * Allocate pointer
01076