utilities.c File Reference

Documented basic utility functions used by other modules of the code. More...

#include "header.h"
Include dependency graph for utilities.c:

Functions

double * make_1Darray (long size)
 Allocate memory to a 1d array of type double and length size. More...
 
int * make_1D_int_array (long size)
 Allocate memory to a 1d array of type integer and length size. More...
 
double ** make_2Darray (long nrows, long ncols)
 Allocate memory to a 2d array of type double. More...
 
void free_2Darray (double **m)
 Free the memory allocated to a 2d array. More...
 
double * init_1Darray (long n, double xmin, double xmax)
 initialize a 1d array, with values in the range of [xmin,xmax] and evenely-space on linear scale More...
 
double * loginit_1Darray (long n, double xmin, double xmax)
 initialize a 1d array, with values in the range of [xmin,xmax] and evenely-space on natural-log scale More...
 
double * log10init_1Darray (long n, double inc, double xmin)
 initialize a 1d array, with values in the range of [xmin,xmax] and evenely-space on log10 scale More...
 
long count_lines_in_file (char *fname)
 Count the number of lines of a file. More...
 
long count_cols_in_file (char *fname)
 Count the number of columns of a file. More...
 

Detailed Description

Documented basic utility functions used by other modules of the code.

Azadeh Moradinezhad Dizgah, November 4th 2021

In summary, the following functions can be called from other modules:

  1. make_1Darray() dynamically allocates memory to a 1d array
  2. make_2Darray() dynamically allocates memory to a 2d array
  3. free_2Darray() free the memory allocated to a 2d array
  4. init_1Darray() initialize a 1d array with linear spacing
  5. loginit_1Darray() initialize a 1d array with natural-log spacing
  6. log10init_1Darray() initialize a 1d array with log10 spacing
  7. count_lines_in_file() count the number of lines of a file
  8. count_cols_in_file() count number of columns of a file
  9. return_arr()

Function Documentation

◆ count_cols_in_file()

long count_cols_in_file ( char *  fname)

Count the number of columns of a file.

Parameters
fnameInput: filename
Returns
long integer value of ncols

◆ count_lines_in_file()

long count_lines_in_file ( char *  fname)

Count the number of lines of a file.

Parameters
fnameInput: filename
Returns
long integer value of nlines
Here is the caller graph for this function:

◆ free_2Darray()

void free_2Darray ( double **  m)

Free the memory allocated to a 2d array.

Parameters
mInput: double pointer to the elements of 2d array
Returns
void

◆ init_1Darray()

double * init_1Darray ( long  n,
double  xmin,
double  xmax 
)

initialize a 1d array, with values in the range of [xmin,xmax] and evenely-space on linear scale

Parameters
nInput: number of elements
xminInput: start point
xmaxInput: end point
Returns
a pointer to a double type 1d array, with values initialized
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log10init_1Darray()

double * log10init_1Darray ( long  n,
double  inc,
double  xmin 
)

initialize a 1d array, with values in the range of [xmin,xmax] and evenely-space on log10 scale

Parameters
nInput: number of elements
incInput: increment
xminInput: start point
Returns
a pointer to a double type 1d array, with values initialized
Here is the call graph for this function:

◆ loginit_1Darray()

double * loginit_1Darray ( long  n,
double  xmin,
double  xmax 
)

initialize a 1d array, with values in the range of [xmin,xmax] and evenely-space on natural-log scale

Parameters
nInput: number of elements
xminInput: start point
xmaxInput: end point
Returns
a pointer to a double type 1d array, with values initialized
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_1D_int_array()

int * make_1D_int_array ( long  size)

Allocate memory to a 1d array of type integer and length size.

Parameters
sizeInput: length of the arrat
Returns
a pointer to an integer type 1d array

◆ make_1Darray()

double * make_1Darray ( long  size)

Allocate memory to a 1d array of type double and length size.

Parameters
sizeInput: length of the array
Returns
a pointer to a 1d array
Here is the caller graph for this function:

◆ make_2Darray()

double ** make_2Darray ( long  nrows,
long  ncols 
)

Allocate memory to a 2d array of type double.

Parameters
nrowsInput: number of rows of the output array
ncolsInput: number of columns of the output array
Returns
a double pointer to a double type 2d array