/* * =================================================================== * Vector Operations and Printing for Matrices of type int * =================================================================== * Copyright (C) 1993-96 by Mark Austin * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written by: M.A. Austin July, 1992 - Jan, 1993 * =================================================================== */ /* #define DEBUG */ #include "matrix.h" #include "vector.h" #include "defs.h" #include /* Error message buffers */ static char buffer1[ MAXTOKSIZE ]; static char buffer2[ MAXTOKSIZE ]; /* * ================================================================= * Print Vector [iLength], where iLength = no items in Vector * ================================================================= */ #ifdef __STDC__ void vecPrintInteger( VECTOR *v ) #else /* Start case not STDC */ void vecPrintInteger(v) VECTOR *v; #endif /* End case not STDC */ { int i; if(v->cpName != NULL) printf ("\nVECTOR \"%s\" \n\n", v->cpName); else printf("\nVECTOR : \"UNTITLED\" cpName \n\n"); for(i = 1; i <= v->iLength; i++) { printf(" %3d ",i); printf(" %16d\n", v->uVector.ip[i-1]); } printf("\n"); } /* * ================================================= * Allocate and Free Vector data structure * ================================================= */ #ifdef __STDC__ int *vecAllocInteger( int iLength ) #else /* Start case not STDC */ int *vecAllocInteger( iLength ) int iLength; #endif /* End case not STDC */ { int *ipArray; ipArray = (int *) safeCalloc( iLength, sizeof(int), __FILE__, __LINE__ ); return (ipArray); } #ifdef __STDC__ void vecFreeInteger( VECTOR *v ) #else /* Start case not STDC */ void vecFreeInteger(v) VECTOR *v; #endif /* End case not STDC */ { free ((char *) v->uVector.ip); free ((char *) v->cpName); free ((char *) v); } /* * ================= * Vector Operations * ================= */ #ifdef __STDC__ VECTOR *vecAddInteger( VECTOR *v1 , VECTOR *v2 ) #else /* Start case not STDC */ VECTOR *vecAddInteger( v1 , v2 ) VECTOR *v1; VECTOR *v2; #endif /* End case not STDC */ { VECTOR *v3; int i; /* [a] : Check Dimensions of Vector */ if(v1->iLength != v2->iLength) { sprintf(buffer1, "Problem : v1->iLength = %4d\n", v1->iLength); sprintf(buffer2, "Problem : v2->iLength = %4d\n", v2->iLength); fatalError("Execution halted in vecAddInteger()", buffer1, buffer2, "Inconsistent Dimensions", (char *) NULL); } /* [b] : Add Vectors */ v3 = vecAlloc((char *) NULL, IntegerArray, v2->iLength); for(i = 1; i <= v2->iLength; i++) v3->uVector.ip[i] = v1->uVector.ip[i] + v2->uVector.ip[i]; return(v3); } #ifdef __STDC__ VECTOR *vecSubInteger( VECTOR *v1 , VECTOR *v2 ) #else /* Start case not STDC */ VECTOR *vecSubInteger(v1, v2) VECTOR *v1; VECTOR *v2; #endif /* End case not STDC */ { VECTOR *v3; int i; /* [a] : Check Dimensions of Vector */ if(v1->iLength != v2->iLength) { sprintf(buffer1, "Problem : v1->iLength = %4d\n", v1->iLength); sprintf(buffer2, "Problem : v2->iLength = %4d\n", v2->iLength); fatalError("Execution halted in vecSubInteger()", buffer1, buffer2, "Inconsistent Dimensions", (char *) NULL); } /* [b] : Add Matrices */ v3 = vecAlloc((char *) NULL, IntegerArray, v2->iLength); for(i = 1; i <= v2->iLength; i++) v3->uVector.ip[i] = v1->uVector.ip[i] - v2->uVector.ip[i]; return(v3); }