/* * ====================================================================== * Vector Operations and Printing for Matrices of type double * ====================================================================== * Copyright (C) 1993-96 by Mark Austin and David Mazzoni. * * 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 MYDEBUG */ #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 vecPrintDouble( VECTOR *v ) #else /* Start case not STDC */ void vecPrintDouble(v) VECTOR *v; #endif /* End case not STDC */ { int i; #ifdef MYDEBUG printf("*** Enter vecPrintDouble() : m->cpName = %s\n", v->cpName); #endif 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(" %16.9e\n", v->uVector.dp[i-1]); } printf("\n"); } /* * ======================================= * Allocate and Free Vector data structure * ======================================= */ #ifdef __STDC__ double *vecAllocDouble( int iLength) #else /* Start case not STDC */ double *vecAllocDouble( iLength) int iLength; #endif /* End case not STDC */ { double *array; array = (double *) safeCalloc( iLength, sizeof(double), __FILE__, __LINE__ ); return (array); } #ifdef __STDC__ void vecFreeDouble( VECTOR *v ) #else /* Start case not STDC */ void vecFreeDouble(v) VECTOR *v; #endif /* End case not STDC */ { free ((char *) v->uVector.dp); free ((char *) v->cpName); free ((char *) v); } /* * ================= * Vector Operations * ================= */ #ifdef __STDC__ VECTOR *vecAddDouble( VECTOR *v1 , VECTOR *v2 ) #else /* Start case not STDC */ VECTOR *vecAddDouble( 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, " : v2->iLength = %4d\n", v2->iLength); fatalError("Execution halted in vecAddDouble()", buffer1, buffer2, "Inconsistent Dimensions", (char *) NULL); } /* [b] : Add Matrices */ v3 = vecAlloc((char *) NULL, DoubleArray, v2->iLength); for(i = 1; i <= v2->iLength; i++) v3->uVector.dp[i] = v1->uVector.dp[i] + v2->uVector.dp[i]; return(v3); } #ifdef __STDC__ VECTOR *vecSubDouble( VECTOR *v1 , VECTOR *v2 ) #else /* Start case not STDC */ VECTOR *vecSubDouble( 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 vecSubDouble()", buffer1, buffer2, "Inconsistent Dimensions", (char *) NULL); } /* [b] : Subtract Matrices */ v3 = vecAlloc((char *) NULL, DoubleArray, v2->iLength); for(i = 1; i <= v2->iLength; i++) v3->uVector.dp[i] = v1->uVector.dp[i] - v2->uVector.dp[i]; return(v3); }