/* Copyright (C) <2003> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA please see full copyright in COPYING file. ------------------------------------------------------------------------- written by A.X. Falcão , March 27th 2003 This program is a collection of basic functions that are useful to all other programs. */ #include "common.h" char *AllocCharArray(int n) { char *v=NULL; v = (char *) calloc(n,sizeof(char)); if (v == NULL) Error(MSG1,"AllocCharArray"); return(v); } uchar *AllocUCharArray(int n) { uchar *v=NULL; v = (uchar *) calloc(n,sizeof(uchar)); if (v == NULL) Error(MSG1,"AllocUCharArray"); return(v); } ushort *AllocUShortArray(int n) { ushort *v=NULL; v = (ushort *) calloc(n,sizeof(ushort)); if (v == NULL) Error(MSG1,"AllocUShortArray"); return(v); } int *AllocIntArray(int n) { int *v=NULL; v = (int *) calloc(n,sizeof(int)); if (v == NULL) Error(MSG1,"AllocIntArray"); return(v); } float *AllocFloatArray(int n) { float *v=NULL; v = (float *) calloc(n,sizeof(float)); if (v == NULL) Error(MSG1,"AllocFloatArray"); return(v); } double *AllocDoubleArray(int n) { double *v=NULL; v = (double *) calloc(n,sizeof(double)); if (v == NULL) Error(MSG1,"AllocDoubleArray"); return(v); } void Error(char *msg,char *func){ /* It prints error message and exits the program. */ fprintf(stderr,"Error:%s in %s\n",msg,func); exit(-1); } void Warning(char *msg,char *func){ /* It prints warning message and leaves the routine. */ fprintf(stdout,"Warning:%s in %s\n",msg,func); } void Change(int *a, int *b){ /* It changes content between a and b */ int c; c = *a; *a = *b; *b = c; } timer *Tic(){ /* It marks the initial time */ timer *tic=NULL; tic = (timer *)malloc(sizeof(timer)); gettimeofday(tic,NULL); return(tic); } timer *Toc(){ /* It marks the final time */ timer *toc=NULL; toc = (timer *)malloc(sizeof(timer)); gettimeofday(toc,NULL); return(toc); } float CTime(timer *tic, timer *toc) /* It computes the time difference */ { float t=0.0; if ((tic!=NULL)&&(toc!=NULL)){ t = (toc->tv_sec-tic->tv_sec)*1000.0 + (toc->tv_usec-tic->tv_usec)*0.001; free(tic);free(toc); tic=NULL; toc=NULL; } return(t); }