/* \input cnoweb Program: weighbor \hfill\break File: matrix.c \hfill\break Author: N. D. Socci \hfill\break Created: 4-Feb-97 \hfill\break \title{matrix.c} \job{Weighbor} \synopsis{Routines for matrix and vector creation and manipulation} */ /*__* *__* *__* WEIGHBOR 1.2 [21-Jun-01] *__* *__* Copyright (c) 1997-2001 *__* Los Alamos National Laboratories *__* The Rockefeller University *__* *__* This file is part of the WEIGHBOR program that can be used free of *__* charge in academic research and teaching. Any commercial use of *__* this software requires prior permission and possibly a license. For *__* commercial use contact: W. Bruno at billb@t10.lanl.gov Los Alamos *__* National Laboratories makes no representations about the *__* suitability of this software for any purpose. It is provided *__* "as is" without express or implied warranty *__* *__* For those using this program for research please use the following *__* citation for this program: *__* *__* Bruno, W. J., Socci, N. D. and Halpern, A. L., ``Weighted *__* Neighbor Joining: A Fast Approximation to Maximum-Likelihood *__* Phylogeny Reconstruction,'' Molecular Biology and Evolution, *__* 17(1): 189-197, (2000). *__* *__* *__*/ /* \section{Introduction} This file contains functions to manipulate the basic vector and matrix data types. */ #include #include #include "matrix.h" #include "weighbor.h" static char version[] __attribute__ ((unused)) = "$Id: matrix.c,v 1.5 2001/06/22 19:05:45 nds Exp $"; /* \section{Constructors and Destructors} Here are the routines for allocating and deallocating matrices and vectors. Note all matrices are square; all matrices and vectors have indices from $0\ldots N-1$ and the matrices are stored in the C convention (row first). */ /* \subsection{matrix} A \|MatrixT| is actually an array of pointers into an $N\times N$ block of memory. The pointers, point to the beginning of each row. It waste some space (ie $N$ pointers) but has some conveniences. Note the matrix idicies go from $0\ldots N-1$; ie the normal \"C" convention. */ MatrixT matrix(int N) { int i,j; MatrixT m; /* Allocate the row pointers */ m = (MatrixT)malloc((size_t)((N)*sizeof(double*))); if(!m) { perror("weighbor::matrix::matrix(1)"); exit(1); } /* Allocate the $N\times N$ block of memory and set pointers*/ m[0] = (double *)malloc((size_t)((N*N)*sizeof(double))); if(!m[0]) { perror("weighbor::matrix::matrix(2)"); exit(1); } for(i=1;ib| and \|c>d| */ double SQR(double a) { return(a*a); } double DMAX(double a, double b) { return( a>b ? a : b ); } double DMIN(double a, double b) { return( a0.0 ? a : 0.0); } /* \endc */