home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * vector allocation and deallocation
- *
- */
-
- /*
- * This software may be freely distributed under the following conditions:
- * 1. It is distributed in its current form, without alterations.
- * 2. No monetary profit is made, under any circumstances.
- *
- * Marc A. Murison
- * Smithsonian Astrophysical Observatory
- * 60 Garden Street, MS 63
- * Cambridge, MA 02138
- *
- * (617) 495-7079 murison@cfacx2.harvard.edu
- */
-
-
- #define global extern
- #define VECTDEF_C
- #include "vectdef.h"
-
-
- /*
- *
- * vector allocation
- *
- */
-
-
- /*
- * allocate a float vector with index range n1 <= i <= n2
- */
- float *fvector( int n1, int n2 )
- {
- float *v;
-
- v = (float *) malloc( (n2-n1+1)*sizeof(float) );
- if( v == NULL )
- verrout( ON, "\nfloat vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate a double vector with index range n1 <= i <= n2
- */
- double *dvector( int n1, int n2 )
- {
- double *v;
-
- v = (double *) malloc( (n2-n1+1)*sizeof(double) );
- if( v == NULL )
- verrout( ON, "\ndouble vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate a character vector with index range n1 <= i <= n2
- */
- char *cvector( int n1, int n2 )
- {
- char *v;
-
- v = (char *) malloc( (n2-n1+1)*sizeof(char) );
- if( v == NULL )
- verrout( ON, "\nchar vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate an unsigned character vector with index range n1 <= i <= n2
- */
- uchar *ucvector( int n1, int n2 )
- {
- uchar *v;
-
- v = (uchar *) malloc( (n2-n1+1)*sizeof(uchar) );
- if( v == NULL )
- verrout( ON, "\nunsigned char vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate an integer vector with index range n1 <= i <= n2
- */
- int *ivector( int n1, int n2 )
- {
- int *v;
-
- v = (int *) malloc( (n2-n1+1)*sizeof(int) );
- if( v == NULL )
- verrout( ON, "\ninteger vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate a short integer vector with index range n1 <= i <= n2
- */
- short int *sivector( int n1, int n2 )
- {
- short int *v;
-
- v = (short int *) malloc( (n2-n1+1)*sizeof(short int) );
- if( v == NULL )
- verrout( ON, "\nshort integer vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate an unsigned short integer vector with index range n1 <= i <= n2
- */
- ushort *usivector( int n1, int n2 )
- {
- ushort *v;
-
- v = (ushort *) malloc( (n2-n1+1)*sizeof(ushort) );
- if( v == NULL )
- verrout( ON,
- "\nunsigned short integer vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate a long integer vector with index range n1 <= i <= n2
- */
- long *lvector( int n1, int n2 )
- {
- long *v;
-
- v = (long *) malloc( (n2-n1+1)*sizeof(long) );
- if( v == NULL )
- verrout( ON, "\nlong vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate an unsigned integer vector with index range n1 <= i <= n2
- */
- uint *uvector( int n1, int n2 )
- {
- uint *v;
-
- v = (uint *) malloc( (n2-n1+1)*sizeof(uint) );
- if( v == NULL )
- verrout( ON, "\nunsigned vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate an unsigned long integer vector with index range n1 <= i <= n2
- */
- ulong *ulvector( int n1, int n2 )
- {
- ulong *v;
-
- v = (ulong *) malloc( (n2-n1+1)*sizeof(ulong) );
- if( v == NULL )
- verrout( ON, "\nunsigned long vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate a Flag vector with index range n1 <= i <= n2
- */
- Flag *flagvector( int n1, int n2 )
- {
- Flag *v;
-
- v = (Flag *) malloc( (n2-n1+1)*sizeof(Flag) );
- if( v == NULL )
- verrout( ON, "\nFlag vector allocation failure!\n" );
- return v-n1;
- }
-
-
- /*
- * allocate a vector of pointers with index range n1 <= i <= n2
- */
- void **pvector( int n1, int n2 )
- {
- void **v;
-
- v = (void **) malloc( (n2-n1+1)*sizeof(char *) );
- if( v == NULL )
- verrout( ON, "\npointer vector allocation failure!\n" );
- return v-n1;
- }
-
-
-
-
- /*
- *
- * vector deallocation
- *
- */
-
-
- /*
- * deallocate a float vector with starting index n1
- */
- void free_fvector( float *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate a double vector with starting index n1
- */
- void free_dvector( double *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate a character vector with starting index n1
- */
- void free_cvector( char *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate an unsigned character vector with starting index n1
- */
- void free_ucvector( uchar *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate an integer vector with starting index n1
- */
- void free_ivector( int *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate a short integer vector with starting index n1
- */
- void free_sivector( short int *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate an unsigned short integer vector with starting index n1
- */
- void free_usivector( ushort *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate a long integer vector with starting index n1
- */
- void free_lvector( long *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate an unsigned vector with starting index n1
- */
- void free_uvector( uint *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate an unsigned long vector with starting index n1
- */
- void free_ulvector( ulong *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate a Flag vector with starting index n1
- */
- void free_flagvector( Flag *v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
- /*
- * deallocate a vector of pointers with starting index n1
- *
- * caller must cast **v as type char before calling this routine
- */
- void free_pvector( char **v, int n1 )
- {
- free( v + n1 );
- return;
- }
-
-
-
-
- /*
- *
- * error output routine
- *
- */
-
- /*-----------------------------------------------------------------------------
- * void verrout( int bell, FILE *device, char *errstring )
- *
- * error output
- *---------------------------------------------------------------------------*/
- void verrout( Boolean bell, char *errstring )
- {
- if( bell ) putchar( BELL );
- printf( "%s", errstring );
- return;
- }
-
-
-
-
-