/* * ====================================================================== * Functions for Vector Operations and Printing * ====================================================================== * 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: Mark Austin July 1992 - October 1993 * ====================================================================== */ #include "matrix.h" #include "vector.h" #include "miscellaneous.h" #include "defs.h" #include /* #define MYDEBUG */ /* Error message buffers */ static char buffer1[ MAXTOKSIZE ]; static char buffer2[ MAXTOKSIZE ]; /* * ================================================================= * Print a Vector [length] * * where -- length = number of items in vector. * ================================================================= */ #ifdef __STDC__ void vecPrint( VECTOR *v ) #else /* Start case not STDC */ void vecPrint(v) VECTOR *v; #endif /* End case not STDC */ { switch((int) v->Type) { case IntegerArray: vecPrintInteger(v); break; case DoubleArray: vecPrintDouble(v); break; default: fatalError("In vecPrint() : Undefined v->Type", (char *) NULL); break; } } /* * ================================================= * Allocate Vector data structure, and array[length] * ================================================= */ #ifdef __STDC__ VECTOR *vecAlloc( char *cpName, DATA_TYPE Type, int iLength) #else /* Start case not STDC */ VECTOR *vecAlloc( cpName, Type, iLength) char *cpName; DATA_TYPE Type; int iLength; #endif /* End case not STDC */ { VECTOR *v; int i; /* Allocate matrix parent data structure, and Name */ v = (VECTOR *) safeMalloc(sizeof(VECTOR), __FILE__, __LINE__ ); if(cpName != NULL) v->cpName = saveString( cpName , __FILE__, __LINE__ ); else v->cpName = (char *) NULL; /* Set parameters and allocate memory for matrix array */ v->Type = Type; v->iLength = iLength; switch((int) v->Type) { case IntegerArray: v->uVector.ip = vecAllocInteger( iLength ); break; case DoubleArray: v->uVector.dp = vecAllocDouble( iLength ); break; default: break; } return (v); } #ifdef __STDC__ void vecFree( VECTOR *v ) #else /* Start case not STDC */ void vecFree( v ) VECTOR *v; #endif /* End case not STDC */ { switch((int) v->Type) { case IntegerArray: vecFreeInteger(v); break; case DoubleArray: vecFreeDouble(v); break; default: fatalError("In Vector_Free() : Undefined v->Type", (char *) NULL); break; } } /* * ================= * Vector Operations * ================= */ #ifdef __STDC__ VECTOR *vecAdd( VECTOR *v1, VECTOR *v2 ) #else /* Start case not STDC */ VECTOR *vecAdd(v1, v2) VECTOR *v1; VECTOR *v2; #endif /* End case not STDC */ { int i,j; switch((int) v1->Type) { case IntegerArray: v1 = vecAddInteger(v1, v2); break; case DoubleArray: v1 = vecAddDouble(v1, v2); break; default: fatalError("In vecAdd() : Undefined v->Type", (char *) NULL); break; } return (v1); } #ifdef __STDC__ VECTOR *vecSub( VECTOR *v1, VECTOR *v2) #else /* Start case not STDC */ VECTOR *vecSub(v1, v2) VECTOR *v1; VECTOR *v2; #endif /* End case not STDC */ { #ifdef DEBUG printf("*** In vecSub() : v1->iLength = %10d\n", v1->iLength); printf(" : v2->iLength = %10d\n", v2->iLength); #endif switch((int) v1->Type) { case IntegerArray: v1 = vecSubInteger(v1, v2); break; case DoubleArray: v1 = vecSubDouble(v1, v2); break; default: fatalError("In vecSub() : Undefined v->Type", (char *) NULL); break; } return (v1); }