/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ /* routine: find_median(), find_percentile(), find_median_of_row() * purpose: compute median of array of double values stored in a 2D array * and return index of closest point. Requires libsort.a routines. * See also: median.c (doesn't require libsort.a, but doesn't return index). * * Michael Borland, 1991, 1995 $Log: rowmedian.c,v $ Revision 1.3 2002/08/14 16:19:00 soliday Added Open License Revision 1.2 1995/09/05 21:20:48 saunders First test release of the SDDS1.5 package. */ #include "mdb.h" long find_median(double *value, double *x, long n) { static double **data = NULL; static long last_n=0; long i; if (n<=0) return(-1); if (n>last_n) { if (data) free_zarray_2d((void**)data, last_n, 2); data = (double**)zarray_2d(sizeof(**data), n, 2); last_n = n; } for (i=0; i100) return -1; if (n>last_n) { if (data) free_zarray_2d((void**)data, last_n, 2); data = (double**)zarray_2d(sizeof(**data), n, 2); last_n = n; } for (i=0; ilast_n) { if (data) free_zarray_2d((void**)data, last_n, 2); data = (double**)zarray_2d(sizeof(**data), n, 2); last_n = n; } for (i=0; i