Data Structures | Defines | Typedefs | Functions | Variables

src/helper.h File Reference

STATUS: stable Helper functions. More...

#include "definitions.h"
#include "escape_codes.h"
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ProgressBarStatus
 status of progress bar. This struct is used as an external variable to keep track of the progress bar. You only need to be concerned about this, if you want to write your own progressbar-function. More...

Defines

#define dprintf(...)
#define ERR_ENDIAN   -6
#define ERR_FATAL   1
#define ERR_GSL   -1
#define ERR_IO   -2
#define ERR_MATLAB   -5
#define ERR_MEM   -4
#define ERR_NOFATAL   0
#define ERR_PARSEMAT   -7
#define ERR_PLOT   -3
#define errprintf(...)
 print error.
#define MALLOC(ptr, nmemb, type)
 convenience memory alloc macro.
#define massert(...)
#define ML(code)
#define NOSTRING   " \b"
#define oprintf(...)
#define PROGRESSBAR_CONTINUE_LONG   2
#define PROGRESSBAR_CONTINUE_SHORT   1
#define PROGRESSBAR_FINISH   3
#define PROGRESSBAR_INIT   0
#define PROGRESSBAR_NUMCOLS   80
#define SWAPT(Type, a, b)   { Type tmp; tmp=(a); (a)=(b); (b)=(tmp); }
 swap two variables.
#define warnprintf(...)
 print warning.

Typedefs

typedef void(* ProgressBarFunction )(int, ulonglong)
 A progressbar-function.

Functions

int compare_ints (const void *a, const void *b)
double ** copy_double_ptrptr (const double **s, int N, int n)
char * create_string (const char *string)
void errormsg (int err_no, int fatal)
size_t ffread (void *ptr, size_t size, size_t nmemb, FILE *stream)
 same as fread, just returning success or failure.
size_t ffwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream)
int is_little_endian ()
bool isin_intarray (const int *a, int n, int val)
void progressbar_rotating (int flag, ulonglong num)
void qsort_int_index (int *idx_idx, const int *idx, int n)
int randint (int from, int to)
int safer_free (void *p)
int strcount (const char *s, char c)
int stream_count_char (FILE *f, char c)
void string_strip_blanks (char *s)
void swap_bytes (void *ptr, int nmemb)
int vprint_vector (const char *name, double *v, int n)
void wswap (void *ptr, int nmemb, int flag)

Variables

ProgressBarStatus progress_status

Detailed Description

STATUS: stable Helper functions.

Definition in file helper.h.


Define Documentation

#define dprintf (   ...  ) 

debugging macros

Definition at line 128 of file helper.h.

#define ERR_ENDIAN   -6

Definition at line 50 of file helper.h.

#define ERR_FATAL   1

Definition at line 52 of file helper.h.

#define ERR_GSL   -1

custom error stuff

Definition at line 45 of file helper.h.

#define ERR_IO   -2

Definition at line 46 of file helper.h.

#define ERR_MATLAB   -5

Definition at line 49 of file helper.h.

#define ERR_MEM   -4

Definition at line 48 of file helper.h.

#define ERR_NOFATAL   0

Definition at line 53 of file helper.h.

#define ERR_PARSEMAT   -7

Definition at line 51 of file helper.h.

#define ERR_PLOT   -3

Definition at line 47 of file helper.h.

#define errprintf (   ...  ) 
Value:
do{ fprintf(stderr, ESCAPE_FGRED_STR ESCAPE_BOLD_STR\
                                              ESCAPE_BGYELLOW_STR "ERROR: %s (%i), %s(): ", \
                                              __FILE__, __LINE__, __FUNCTION__);    \
     fprintf(stderr, ## __VA_ARGS__);                                               \
     fprintf(stderr, NOSTRING ESCAPE_RESET_STR); } while(0)

print error.

Report an Error.

Definition at line 136 of file helper.h.

#define MALLOC (   ptr,
  nmemb,
  type 
)
Value:
ptr = (type*)malloc(nmemb*sizeof(type));            \
  if( ptr==NULL ){                                          \
     errprintf("Could not allocate memory\n");      \
  }

convenience memory alloc macro.

use as follows:

        double *a;
        MALLOC( a, 100, double );
        double **b;
        MALLOC( b, 100, double* ); 

Definition at line 98 of file helper.h.

#define massert (   ...  ) 

Definition at line 129 of file helper.h.

#define ML (   code  ) 

Definition at line 41 of file helper.h.

#define NOSTRING   " \b"

Definition at line 55 of file helper.h.

#define oprintf (   ...  ) 
Value:
do{ fprintf(stderr, ESCAPE_FGCYAN_STR ESCAPE_BRIGHT_STR \
                                            "%s (%i), %s() --> ",                       \
                                            __FILE__, __LINE__, __FUNCTION__);      \
     fprintf(stderr, ## __VA_ARGS__);                                               \
     fprintf(stderr, NOSTRING ESCAPE_RESET_STR); } while(0)

Definition at line 149 of file helper.h.

#define PROGRESSBAR_CONTINUE_LONG   2

continue flag for progress bar, major step

Definition at line 60 of file helper.h.

#define PROGRESSBAR_CONTINUE_SHORT   1

continue flag for progress bar, minor step

Definition at line 59 of file helper.h.

#define PROGRESSBAR_FINISH   3

cleanup

Definition at line 61 of file helper.h.

#define PROGRESSBAR_INIT   0

initialize flag for progress bar

Definition at line 58 of file helper.h.

#define PROGRESSBAR_NUMCOLS   80

number of columns for progress bar

Definition at line 57 of file helper.h.

#define SWAPT (   Type,
  a,
  b 
)    { Type tmp; tmp=(a); (a)=(b); (b)=(tmp); }

swap two variables.

Definition at line 65 of file helper.h.

#define warnprintf (   ...  ) 
Value:
do{ fprintf(stderr, ESCAPE_FGWHITE_STR ESCAPE_BOLD_STR \
                                                ESCAPE_BGBLUE_STR "WARNING: %s (%i), %s(): ", \
                                                __FILE__, __LINE__, __FUNCTION__);  \
     fprintf(stderr, ## __VA_ARGS__);                                               \
     fprintf(stderr, NOSTRING ESCAPE_RESET_STR); } while(0)

print warning.

Definition at line 143 of file helper.h.


Typedef Documentation

typedef void(* ProgressBarFunction)(int, ulonglong)

A progressbar-function.

Definition at line 86 of file helper.h.


Function Documentation

int compare_ints ( const void *  a,
const void *  b 
)

Definition at line 159 of file helper.c.

double** copy_double_ptrptr ( const double **  s,
int  N,
int  n 
)

deep copy of double ptrptr

Definition at line 60 of file helper.c.

char* create_string ( const char *  string  ) 

Definition at line 21 of file helper.c.

void errormsg ( int  err_no,
int  fatal 
)

Definition at line 186 of file helper.c.

size_t ffread ( void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)

same as fread, just returning success or failure.

Definition at line 92 of file helper.c.

size_t ffwrite ( const void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)

Definition at line 99 of file helper.c.

int is_little_endian (  ) 

Definition at line 145 of file helper.c.

bool isin_intarray ( const int *  a,
int  n,
int  val 
)

checks whether val is in a.

Definition at line 30 of file helper.c.

void progressbar_rotating ( int  flag,
ulonglong  num 
)

displays a progress-bar like this

     [ #####\                          ]
Parameters:
flag one of PROGRESSBAR_INIT, PROGRESSBAR_CONTINUE_LONG, PROGRESSBAR_CONTINUE_SHORT
num meaning depends on flag

Definition at line 236 of file helper.c.

void qsort_int_index ( int *  idx_idx,
const int *  idx,
int  n 
)

Definition at line 112 of file helper.c.

int randint ( int  from,
int  to 
)

returns a random integer in the range [from, from+1, ..., to]

Definition at line 53 of file helper.c.

int safer_free ( void *  p  ) 

checks whether p is the NULL pointer before freeing.

Returns:
0 memory was freed, 1 no memory was freed

Definition at line 42 of file helper.c.

int strcount ( const char *  s,
char  c 
)

count the number of occurences of c in s

Parameters:
s - the string ( terminated)
c - the character
Returns:
count( s==c )

Definition at line 219 of file helper.c.

int stream_count_char ( FILE *  f,
char  c 
)

return number of occurences of c in f. f is rewound to current position

Definition at line 77 of file helper.c.

void string_strip_blanks ( char *  s  ) 

remove spaces from a string by "compressing" it. for example, " this is a bla nk" becomes "thisisablank"

Definition at line 284 of file helper.c.

void swap_bytes ( void *  ptr,
int  nmemb 
)

Definition at line 133 of file helper.c.

int vprint_vector ( const char *  name,
double *  v,
int  n 
)

Definition at line 176 of file helper.c.

void wswap ( void *  ptr,
int  nmemb,
int  flag 
)

wrapper

Definition at line 172 of file helper.c.


Variable Documentation

Definition at line 17 of file helper.c.