www.pudn.com > SMV_Code.rar > gputil.c
/*=========================================================================*/
/* Each of the companies; Ericsson, Lucent, Mindspeed, Motorola, Nokia, */
/* Nortel Networks, and Qualcomm (hereinafter referred to individually as */
/* “Source” or collectively as “Sources”) do hereby state: */
/* */
/* To the extent to which the Source(s) may legally and freely do so, */
/* the Source(s), upon submission of a Contribution, grant(s) a free, */
/* irrevocable, non-exclusive, license to the Third Generation Partnership */
/* Project 2 (3GPP2) and its Organizational Partners: ARIB, CCSA, TIA, */
/* TTA, and TTC, under the Source’s copyright or copyright license rights */
/* in the Contribution, to, in whole or in part, copy, make derivative */
/* works, perform, display and distribute the Contribution and derivative */
/* works thereof consistent with 3GPP2’s and each Organizational Partner’s */
/* policies and procedures, with the right to (i) sublicense the foregoing */
/* rights consistent with 3GPP2’s and each Organizational Partner’s */
/* policies and procedures and (ii) copyright and sell, if applicable) in */
/* 3GPP2's name or each Organizational Partner’s name any 3GPP2 or */
/* transposed Publication even though this Publication may contain the */
/* Contribution or a derivative work thereof. The Contribution shall */
/* disclose any known limitations on the Source’s rights to license as */
/* herein provided. */
/* */
/* When a Contribution is submitted by the Source(s) to assist the */
/* formulating groups of 3GPP2 or any of its Organizational Partners, */
/* it is proposed to the Committee as a basis for discussion and is not */
/* to be construed as a binding proposal on the Source(s). The Source(s) */
/* specifically reserve(s) the right to amend or modify the material */
/* contained in the Contribution. Nothing contained in the Contribution */
/* shall, except as herein expressly provided, be construed as conferring */
/* by implication, estoppel or otherwise, any license or right under */
/* (i) any existing or later issuing patent, whether or not the use of */
/* information in the document necessarily employs an invention of any */
/* existing or later issued patent, (ii) any copyright, (iii) any */
/* trademark, or (iv) any other intellectual property right. */
/* */
/* With respect to the Software necessary for the practice of any or all */
/* Normative portions of the Selectable Mode Vocoder (SMV) as it exists on */
/* the date of submittal of this form, should the SMV be approved as a */
/* Specification or Report by 3GPP2, or as a transposed Standard by any of */
/* the 3GPP2’s Organizational Partners, the Source(s) state(s) that a */
/* worldwide license to reproduce, use and distribute the Software, the */
/* license rights to which are held by the Source(s), will be made */
/* available to applicants under terms and conditions that are reasonable */
/* and non-discriminatory, which may include monetary compensation, */
/* and only to the extent necessary for the practice of any or all of the */
/* Normative portions of the SMV or the field of use of practice of the */
/* SMV Specification, Report, or Standard. The statement contained above */
/* is irrevocable and shall be binding upon the Source(s). In the event */
/* the rights of the Source(s) in and to copyright or copyright license */
/* rights subject to such commitment are assigned or transferred, */
/* the Source(s) shall notify the assignee or transferee of the existence */
/* of such commitments. */
/*=========================================================================*/
/* */
/*-------------------------------------------------------------------*/
/*===================================================================*/
/* LIBRARY: gputil.c */
/*-------------------------------------------------------------------*/
/* PURPOSE : General Purpose Library. */
/*===================================================================*/
/*----------------------------------------------------------------------------*/
/*-------------------------------- INCLUDE -----------------------------------*/
/*----------------------------------------------------------------------------*/
#include "typedef.h"
#include "main.h"
#include "mcutil.h"
#include "gputil.h"
#ifdef WMOPS
#include "const.h"
#include "lib_wmp.h"
#endif
/*----------------------------------------------------------------------------*/
/*------------------------------ FUNCTIONS -----------------------------------*/
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTIONS : file_open_rb () */
/*-------------------------------------------------------------------*/
/* PURPOSE : These functions open the file named file_name,*/
/* and return a pointer to this file. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ file name. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ pointer to the file. */
/*===================================================================*/
FILE *file_open_rb ( char *file_name )
{
/*-------------------------------------------------------------------*/
FILE *file_ptr;
/*-------------------------------------------------------------------*/
if ( (file_ptr = fopen ( file_name, "rb" ) ) == NULL)
{
#ifdef VERBOSE
printf("\nfile name : %s\n", file_name);
nrerror ("error opening file (rb) ...");
#else
exit(1);
#endif
}
/*-------------------------------------------------------------------*/
return (file_ptr);
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTIONS : file_open_wb () */
/*-------------------------------------------------------------------*/
/* PURPOSE : These functions open the file named file_name,*/
/* and return a pointer to this file. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ file name. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ pointer to the file. */
/*===================================================================*/
FILE *file_open_wb ( char *file_name )
{
/*-------------------------------------------------------------------*/
FILE *file_ptr;
/*-------------------------------------------------------------------*/
if ( (file_ptr = fopen ( file_name, "wb" ) ) == NULL)
{
#ifdef VERBOSE
printf("\nfile name : %s\n", file_name);
nrerror ("error opening file (wb) ...");
#else
exit(1);
#endif
}
/*-------------------------------------------------------------------*/
return (file_ptr);
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : ini_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function initializes a vector of FLOAT64 */
/* to a given value. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/* _ (FLOAT64) val */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) initialized v vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void ini_dvector ( FLOAT64 *v, INT32 nl, INT32 nh, FLOAT64 val )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_move(nh-nl+1);
#endif
for (i = nl; i <= nh; i ++)
v [i] = val;
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
#ifdef WMOPS
/*===================================================================*/
/* FUNCTION : ini_lvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function initializes a vector of INT64 */
/* to a given value. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (INT64 *) v vector of int. */
/* _ (INT32 ) nl */
/* _ (INT32 ) nh */
/* _ (INT32 ) val */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (INT64 *) initialized v vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void ini_lvector ( INT64 *v, INT32 nl, INT32 nh, INT64 val )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
for (i = nl; i <= nh; i ++)
v [i] = val;
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
#endif
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : ini_svector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function initializes a vector of INT16 */
/* to a given value. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (INT16 *) v vector of int. */
/* _ (INT32 ) nl */
/* _ (INT32 ) nh */
/* _ (INT16 ) val */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (INT16 *) initialized v vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void ini_svector ( INT16 *v, INT32 nl, INT32 nh, INT16 val )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
for (i = nl; i <= nh; i ++)
v [i] = val;
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : cpy_svector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function writes v1 to v2. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (INT16 *) v1 vector of short. */
/* _ (INT16 *) v2 vector of short. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (INT16*) new v2 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void cpy_svector ( INT16 *v1, INT16 *v2, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
for (i = nl; i <= nh; i ++)
v2 [i] = v1 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : cpy_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function writes v1 to v2. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64*) v2 vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) new v2 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void cpy_dvector ( FLOAT64 *v1, FLOAT64 *v2, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_move (nh-nl+1);
#endif
for (i = nl; i <= nh; i ++)
v2 [i] = v1 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : sfr_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function shift roigth v elements of n */
/* position. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (INT32) n number of rigth shift */
/* _ (INT32) nl lower index */
/* _ (INT32) nh higher index */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) v2 shifted rigth v1 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void sfr_dvector ( FLOAT64 *v1, FLOAT64 *v2, INT32 n, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_move (nh-n-nl+1);
#endif
for (i = nh-n; i >= nl; i --)
v2 [i+n] = v1 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : rev_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function reverse the order of the */
/* elements of a vector. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (INT32) nl lower index */
/* _ (INT32) nh higher index */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) v2 reversed v1 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void rev_dvector ( FLOAT64 *v1, FLOAT64 *v2, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
for (i = nl; i <= nh; i++)
v2 [i] = v1 [nh-i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : sca_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function scale v1 into v2 by the factor */
/* s. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64) s scale factor. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) v2 scaled vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void sca_dvector ( FLOAT64 *v1, FLOAT64 s, FLOAT64 *v2, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_mult (nh-nl+1);
WMP_cnt_move (nh-nl+1);
#endif
for (i = nl; i <= nh; i ++)
v2 [i] = s * v1 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : dot_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function calculate the dot product */
/* between v1 and v2 */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64*) v2 vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ (FLOAT64 *) s dot product. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void dot_dvector ( FLOAT64 *v1, FLOAT64 *v2, FLOAT64 *s, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_move (1);
WMP_cnt_mac (nh-nl+1);
#endif
(*s) = 0.0;
for (i = nl; i <= nh; i ++)
(*s) += v1 [i] * v2 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : add_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function adds v1 to v2 in v. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64*) v2 vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) v=v1+v2 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void add_dvector (FLOAT64 *v1, FLOAT64 *v2, FLOAT64 *v, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_add (nh-nl+1);
WMP_cnt_move (nh-nl+1);
#endif
for (i = nl; i <= nh; i ++)
v [i] = v1 [i] + v2 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : wad_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function adds v1 to v2 in v. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64 ) w1 weigth for v1. */
/* _ (FLOAT64*) v2 vector of double. */
/* _ (FLOAT64 ) w2 weigth for v2. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) v = w1 * v1 + w2 * v2 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void wad_dvector ( FLOAT64 *v1, FLOAT64 w1, FLOAT64 *v2, FLOAT64 w2,
FLOAT64 *v, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_mult (nh-nl+1);
WMP_cnt_mac (nh-nl+1);
WMP_cnt_move (nh-nl+1);
#endif
for (i = nl; i <= nh; i ++)
v [i] = w1 * v1 [i] + w2 * v2 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : mul_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function multiply v1 by v2 in v. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64*) v2 vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) v=v1*v2 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void mul_dvector (FLOAT64 *v1, FLOAT64 *v2, FLOAT64 *v, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_mult(nh-nl+1);
WMP_cnt_move(nh-nl+1);
#endif
for (i = nl; i <= nh; i ++)
v [i] = v1 [i] * v2 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : dif_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function substracts v2 to v1 into v. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64*) v2 vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) v=v1-v2 vector. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void dif_dvector (FLOAT64 *v1, FLOAT64 *v2, FLOAT64 *v, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_sub (nh-nl+1);
WMP_cnt_move (nh-nl+1);
#endif
for (i = nl; i <= nh; i ++)
v [i] = v1 [i] - v2 [i];
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : abs_max_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function finds the absolute maximum of a */
/* vector. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64) max value. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void abs_max_dvector (FLOAT64 *v, FLOAT64 *max, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_test (2*(nh-nl+1));
WMP_cnt_move (nh-nl+1);
#endif
*max = 0.0;
for (i = nl; i <= nh; i ++){
if(v[i] > *max)
*max = v[i];
else if(-v[i] > *max)
*max = -v[i];
}
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : max_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function finds the maximum of v. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) max. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void max_dvector ( FLOAT64 *v, FLOAT64 *max, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_test (nh-nl);
WMP_cnt_move (nh-nl+1);
#endif
for ( i = nl+1, *max = *(v+nl); i <= nh; i ++ )
*max = ((*(v+i) > *max) ? *(v+i) : *max);
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : min_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function finds the minimum of v. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64*) min. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void min_dvector ( FLOAT64 *v, FLOAT64 *min, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_test (nh-nl);
WMP_cnt_move (nh-nl+1);
#endif
for (i = nl+1, *min = *(v+nl); i <= nh; i ++ )
(*min) = ((*(v+i) < *min) ? *(v+i) : *min);
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : sum_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function sums the elements of a vector. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64) sum value. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void sum_dvector (FLOAT64 *v, FLOAT64 *sum, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_move (1);
WMP_cnt_add (nh-nl);
#endif
*sum = v[nl];
for (i = nl+1; i <= nh; i ++){
*sum += v[i];
}
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : se_dvector (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function calculates the squared error */
/* between two vectors. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : _ (FLOAT64*) v1 vector of double. */
/* _ (FLOAT64*) v2 vector of double. */
/* _ (INT32) nl */
/* _ (INT32) nh */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : _ (FLOAT64) error value. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : _ None. */
/*===================================================================*/
void se_dvector (FLOAT64 *v1, FLOAT64 *v2, FLOAT64 *error, INT32 nl, INT32 nh )
{
/*-------------------------------------------------------------------*/
INT32 i;
/*-------------------------------------------------------------------*/
#ifdef WMOPS
WMP_cnt_mac (nh-nl+1);
#endif
*error = (v1[nl]-v2[nl])*(v1[nl]-v2[nl]);
for (i = nl+1; i <= nh; i ++){
*error += (v1[i]-v2[i])*(v1[i]-v2[i]);
}
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*============================================================================*/
/*------------------------------------- END ----------------------------------*/
/*============================================================================*/