segStdLib.h File Reference

Handy macro-functions and a header for the standard function library for SEGRec. More...

Go to the source code of this file.

Defines

#define xcalloc(n, t)   ((t*)calloc((n),sizeof(t)))
#define xmalloc(n, t)   ((t*)malloc((n)*sizeof(t)))
#define xfree(p)   free((char*)(p))
#define max(a, b)   (((a)>(b))?(a):(b))
#define min(a, b)   (((a)<(b))?(a):(b))
#define fswap(a, b)   {double tmp=(a);(a)=(b);(b)=tmp}
#define iswap(a, b)   {long tmp=(a);(a)=(b);(b)=tmp}
#define sign(a)   ((a)==0.0?0.0:(a)<0.0?-1.0:1.0)
#define setzero(p, n)   memset((p),0,sizeof(p[0])*(n))
#define numel(a)   ((int)(sizeof(a)/sizeof(a[0])))
#define bswap32(a)   (((unsigned long)(a)>>24)|(((unsigned long)(a)&0x00ff0000)>>8)|(((unsigned long)(a)&0x0000ff00)<<8)|((unsigned long)(a)<<24))
#define bswap16(a)   (((unsigned short)(a)>>8)|((unsigned short)(a)<<8))
#define TRUE   (-1)
#define FALSE   (0)

Functions

double logProb (double prob)
 Logarithmic operation for probability calculation.
double ** allocDblMatrix (int nrow, int ncol)
 Allocate memory for an (nrow x ncol) matrix.
void freeDblMatrix (double **mat, int nrow)
 Free memory space of a matrix.
int ** allocIntMatrix (int nrow, int ncol)
 Allocate memory for an (nrow x ncol) matrix.
void freeIntMatrix (int **mat, int nrow)
 Free memory space of a matrix.
short ** allocShtMatrix (int nrow, int ncol)
 Allocate memory for an (nrow x ncol) matrix.
void freeShtMatrix (short **mat, int nrow)
 Free memory space of a matrix.
long ** allocLngMatrix (int nrow, int ncol)
 Allocate memory for an (nrow x ncol) matrix.
void freeLngMatrix (long **mat, int nrow)
 Free memory space of a matrix.
int countLines (FILE *)
 Count the number of lines in a text file.
int probeWord (char *word, int size, FILE *fp)
 Read a word from a given file pointer without incrementing the pointer.
char * allocCopyStr (char *source)
 Allocate memory space and copy a string to the space.
char * extractLastDiphone (char *label)
 Extract the last diphone from a given triphone.
char * extractFirstDiphone (char *label)
 Extract the first diphone included in the triphone.
char * extractCentrePhone (char *label)
 Extract the centre phone of the triphone.


Detailed Description

Handy macro-functions and a header for the standard function library for SEGRec.

Author:
Yoshinori Shiga @ CVSSP, University of Surrey
Revision

Function Documentation

char* allocCopyStr ( char *  source  ) 

Allocate memory space and copy a string to the space.

Parameters:
[in] source 
Return values:
NULL Memory allocation error
otherwise Pointer to the string copied
Author:
Yoshinori Shiga @ CVSSP, University of Surrey
Note:
This function allocates memory with just the length of the input string, and copies the string to the space.

double** allocDblMatrix ( int  nrow,
int  ncol 
)

Allocate memory for an (nrow x ncol) matrix.

Parameters:
[in] nrow Number of rows
[in] ncol Number of columns
Return values:
NULL Memory allocation error
otherwise Pointer to the matrix allocated
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

int** allocIntMatrix ( int  nrow,
int  ncol 
)

Allocate memory for an (nrow x ncol) matrix.

Parameters:
[in] nrow Number of rows
[in] ncol Number of columns
Return values:
NULL Memory allocation error
otherwise Pointer to the matrix allocated
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

long** allocLngMatrix ( int  nrow,
int  ncol 
)

Allocate memory for an (nrow x ncol) matrix.

Parameters:
[in] nrow Number of rows
[in] ncol Number of columns
Return values:
NULL Memory allocation error
otherwise Pointer to the matrix allocated
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

short** allocShtMatrix ( int  nrow,
int  ncol 
)

Allocate memory for an (nrow x ncol) matrix.

Parameters:
[in] nrow Number of rows
[in] ncol Number of columns
Return values:
NULL Memory allocation error
otherwise Pointer to the matrix allocated
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

int countLines ( FILE *  ip  ) 

Count the number of lines in a text file.

Parameters:
[in] ip File pointer to the file
Returns:
Number of lines
Author:
Yoshinori Shiga @ CVSSP, University of Surrey
Note:
The function parse text of the file, and count the number of lines of the text. The file pointer is so rewound as to point the top of the file at the end.

char* extractCentrePhone ( char *  label  ) 

Extract the centre phone of the triphone.

Parameters:
[in] label Triphone label
Returns:
Pointer to the diphone
Author:
Yoshinori Shiga @ CVSSP, University of Surrey
Note:
This function overwrite the input character array.
Functions extractLastDiphone() and
extractFirstDiphone() are called internally.
See also:
extractLastDiphone() and extractFirstDiphone()

char* extractFirstDiphone ( char *  label  ) 

Extract the first diphone included in the triphone.

Parameters:
[in] label Triphone label
Returns:
Pointer to the diphone
Author:
Yoshinori Shiga @ CVSSP, University of Surrey
Note:
This function overwrite the input character array.

char* extractLastDiphone ( char *  label  ) 

Extract the last diphone from a given triphone.

Parameters:
[in] label Triphone label
Returns:
Pointer to the diphone
Author:
Yoshinori Shiga @ CVSSP, University of Surrey
Note:
This function overwrite the input character array.

void freeDblMatrix ( double **  mat,
int  nrow 
)

Free memory space of a matrix.

Parameters:
[in] mat Pointer to the matrix
[in] nrow Number of rows
Returns:
No return value
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

void freeIntMatrix ( int **  mat,
int  nrow 
)

Free memory space of a matrix.

Parameters:
[in] mat Pointer to the matrix
[in] nrow Number of rows
Returns:
No return value
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

void freeLngMatrix ( long **  mat,
int  nrow 
)

Free memory space of a matrix.

Parameters:
[in] mat Pointer to the matrix
[in] nrow Number of rows
Returns:
No return value
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

void freeShtMatrix ( short **  mat,
int  nrow 
)

Free memory space of a matrix.

Parameters:
[in] mat Pointer to the matrix
[in] nrow Number of rows
Returns:
No return value
Author:
Yoshinori Shiga @ CVSSP, University of Surrey

double logProb ( double  prob  ) 

Logarithmic operation for probability calculation.

Parameters:
[in] prob Probability
Returns:
Natural-logarithm of the probability
Author:
Yoshinori Shiga @ CVSSP, University of Surrey
Note:
The maximum value of the ouput is BIGNUM.

int probeWord ( char *  word,
int  size,
FILE *  fp 
)

Read a word from a given file pointer without incrementing the pointer.

Parameters:
[in,out] word Pointer to an array to which a read word is stored
[in] size Maximum possible length of the word in byte
[in] fp File pointer from which the word is read
Return values:
ERROR_FREAD File read error
ERROR_ALLOC Memory allocation error
RTN_ERROR Error: bad file format
NO_ERROR Successful execution
Author:
Yoshinori Shiga @ CVSSP, University of Surrey


Generated on Sun Aug 5 02:40:37 2007 for SEGRec Version 1.0 by  doxygen 1.5.1