helperfunc.h File Reference

header file for helper functions More...

#include <string>
#include <vector>
#include "Matrix.h"
#include "Cvals.h"

Include dependency graph for helperfunc.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  array_data

Defines

#define M_PI   3.1415926535897932385

Functions

void * alloc_1d_array (int size, int type)
struct array_data alloc_mem (int dimension, int type,...)
void * shift_pointer (void *pointer, int type, int num)
void set_pointer_pointer_val (void *pointer, int type, void *val)
void * get_pointer_pointer_val (void *pointer, int type)
void print_alloc_data (struct array_data arr)
void check_pointer_sanity (void *pointer, const char *func)
void print_pointer_val (void *pointer, int type)
void free_mem (struct array_data arr)
int gridder (int nx, int ny, int ndata, int offset[3], int jump[3], double xmin, double xmax, double ymin, double ymax, float *xval, float *yval, float *val, float *xsep, float *ysep, float **results)
int gridder (int nx, int ny, int ndata, int offset[3], int jump[3], double xmin, double xmax, double ymin, double ymax, float *xval, float *yval, float *val, vector< float > &xsep, vector< float > &ysep, Matrix< float > &results, Matrix< int > &number)
int gridder (int nx, int ny, int ilow, int ihigh, double xmin, double xmax, double ymin, double ymax, Cvals *xval, Cvals *yval, Cvals *val, vector< float > &xsep, vector< float > &ysep, Matrix< float > &results, Matrix< int > &number)
double get_upbnd_bin_linear (int nbins, double xmin, double xmax, int bin)
double get_lowbnd_bin_linear (int nbins, double xmin, double xmax, int bin)
int get_bin_number_linear (int nbins, double xmin, double xmax, double xval)
double get_center_bin_linear (int nbins, double xmin, double xmax, int bin)
float * al1df (int nval)
void fr1df (float *pointer)
float ** al2df (int nrow, int ncol)
void fr2df (float **pointer, int ncol)
void flhunt (float *xx, int n, float x, int *jlo)
void flhunt (vector< float > xx, int n, float x, int *jlo)
void convolve_2d_standard (std::string type, Matrix< float > &matrix, vector< float > xvals, vector< float > yvals, std::vector< double > parameters)
void convolve_2d_standard_gaussian (float *array, int nrow, int ncol, const vector< float > &xvals, const vector< float > &yvals, double xsigma, double ysigma, const double &gauss_cut)
void convolve_2d_standard_gaussian (Matrix< float > &matrix, const vector< float > &xvals, const vector< float > &yvals, double xsigma, double ysigma, const double &gauss_cut=0.)
void convolve_2d_standard_gaussian_row (unsigned n, Matrix< float > &matrix, Matrix< float > &temp, const vector< float > &xvals, const vector< float > &yvals, double xsigma, double ysigma, const int &xcut, const int &ycut)
void convolve_2d_standard_gaussian_point (unsigned n, unsigned m, Matrix< float > &matrix, Matrix< float > &temp, const vector< float > &xvals, const vector< float > &yvals, double xsigma, double ysigma, const int &xcut, const int &ycut)
void convolve_2d_standard_gaussian_varsig (unsigned n, unsigned m, Matrix< float > &matrix, Matrix< float > &temp, const Matrix< float > &xsig, const Matrix< float > &ysig, const vector< float > &xvals, const vector< float > &yvals)
void test_convolution (void)


Detailed Description

header file for helper functions


Function Documentation

float* al1df ( int  nval  ) 

1D float array functions

Allocate a 1-dimensional float array of nval spaces. Returns a pointer to the array. On error: prints a warning and shuts down the program ^^

float** al2df ( int  nrow,
int  ncol 
)

2D float array functions

Allocate a 2-dimensional float array of nval spaces. Returns a pointer to the array. No effort is done to keep the memory (the rows) consecutive in memory.

On error: prints a warning and shuts down the program ^^

void* alloc_1d_array ( int  size,
int  type 
)

function to allocate a 1-D array

Parameters:
size size of the array
type type of the array:
negative number: pointer to this type (e.g. -1: type *int)
  • 1 : int
  • 2 : float
  • 3 : double
  • 4 : char

struct array_data alloc_mem ( int  dimension,
int  type,
  ... 
) [read]

This is the mother routine, should be used for all allocating. The arguments:

Parameters:
dimension the dimension of the array (e.g. an array[][][]: dimension 3)
type type of the array. This is an integer. For a list of the types: see alloc_1D_array
... list of the sizes of each individual dimension.
Eample: to allocate an integer 4x5x2 array: alloc_mem(3, 1, 4,5,2); The resulting struct can then be used as: (e.g. struct array_data tmp): ((double ***)tmp.arr)[0][1][2]

note: memory is not allocated consecutive in the memory, e.g. the rows of the allocated array do not necessarily form 1 block in the memory (a row by itself is consecutive of course).

void check_pointer_sanity ( void *  pointer,
const char *  func 
)

check if the pointer is zero

void convolve_2d_standard_gaussian ( Matrix< float > &  matrix,
const vector< float > &  xvals,
const vector< float > &  yvals,
double  xsigma,
double  ysigma,
const double &  gauss_cut 
)

gauss_cut set this value if no smoothing is to be done when the value of the gaussian drops below this value. This limits the smoothing of a point to an area around this point instead of smoothing to the entire region. Note: it is set to zero as default i.e. smooth over entire region

*** Works only on a grid with equal x-spacing everywhere, also equal *** y-spacing everywhere (e.g. xvals[i]-xvals[i-1] is constant).

convolving a 2D grid with a 2D gaussian: consists of the discrete sum over the indices, multiplying the values of the grid with the values of the respective integrals of the 2D gaussian functions over the grid cell. We thus seem to be dealing with a discrete convolution, that is only because the integrals (from our continuous convolution) reduce to integrating the error function in the cells and then adding results from the entire domain.

This function first constructs a 2D grid of the integrated gaussian function. This grid is for x>0 and y>0. The leftmost column grid-cells are (xvals[i]-xvals[i-1])/2. wide, same for the y-width of the bottom row. This because the origin of this grid (0,0) should ly in the middle of a grid cell. We then multiply the gaussian integral for all the edge cells by 2, for the origin cell by 4. These edge cells thus ly half in x>0,y>0 and half in either x>0,y<0 or x<0,y>0. The origin cell lies in all 4 regions.

After the grid is constructed (using the error function for integration, and subtracting cells from each-other to get the integral in a cell) each cell of the input matrix is convolved with this gaussian grid.

void convolve_2d_standard_gaussian ( float *  array,
int  nrow,
int  ncol,
const vector< float > &  xvals,
const vector< float > &  yvals,
double  xsigma,
double  ysigma,
const double &  gauss_cut 
)

overloaded version that is able to operate on a pointer. Should never use this unless you are really stuck with float pointers, use the one with the matrix instead.

void flhunt ( vector< float >  xx,
int  n,
float  x,
int *  jlo 
)

vector version Given an array xx[0..n-1], and given a value x, returns a value jlo such that x is between xx[jlo] and xx[jlo+1]. xx[0..n-1] must be monotonic, either increasing or decreasing. jlo=-1 or jlo=n-1 is returned to indicate that x is out of range. jlo on input is taken as the initial guess for jlo on output.

used to be a nr function, replaced because of the licencing

void flhunt ( float *  xx,
int  n,
float  x,
int *  jlo 
)

float version Given an array xx[0..n-1], and given a value x, returns a value jlo such that x is between xx[jlo] and xx[jlo+1]. xx[0..n-1] must be monotonic, either increasing or decreasing. jlo=-1 or jlo=n-1 is returned to indicate that x is out of range. jlo on input is taken as the initial guess for jlo on output.

void free_mem ( struct array_data  arr  ) 

Use this routine to free the memory previously allocated by alloc_mem

int get_bin_number_linear ( int  nbins,
double  xmin,
double  xmax,
double  xval 
)

return the bin number for an xvalue between xmin and xmax, with nbins bins. the scale is linear. A value of xmin returns 0, a value of xmax returns nbins - 1. (xmax would normally return nbins but is modified by hand to avoid segfaults)

double get_center_bin_linear ( int  nbins,
double  xmin,
double  xmax,
int  bin 
)

returns the center value of a bin. bins: between 0 and nbins-1

void* get_pointer_pointer_val ( void *  pointer,
int  type 
)

assuming "pointer" is a pointer to a pointer, get the value of this last pointer

int gridder ( int  nx,
int  ny,
int  ndata,
int  offset[3],
int  jump[3],
double  xmin,
double  xmax,
double  ymin,
double  ymax,
float *  xval,
float *  yval,
float *  val,
vector< float > &  xsep,
vector< float > &  ysep,
Matrix< float > &  results,
Matrix< int > &  number 
)

overloaded: uses a Matrix for the results. See the file info for details. ilow, ihigh: loop over the particle numbers [ilow, ihigh[

int gridder ( int  nx,
int  ny,
int  ndata,
int  offset[3],
int  jump[3],
double  xmin,
double  xmax,
double  ymin,
double  ymax,
float *  xval,
float *  yval,
float *  val,
float *  xsep,
float *  ysep,
float **  results 
)

Allows you to distribute any quantity you want to a 2D grid

void print_alloc_data ( struct array_data  arr  ) 

use this routine to print information about an allocated array_data struct: information about the dimension, column sizes, adresses of the array locations and the actual values stored in the array

void print_pointer_val ( void *  pointer,
int  type 
)

assuming pointer is a pointer to a variable, print the value of this variable

void set_pointer_pointer_val ( void *  pointer,
int  type,
void *  val 
)

Set the value of the pointer to which the argument pointer points (that's a lot of pointers in one sentence :D)

void* shift_pointer ( void *  pointer,
int  type,
int  num 
)

shift a pointer of type "type" num spaces


Generated on Fri Oct 16 18:59:58 2009 for HYPLOT by  doxygen 1.5.8