STATUS: stable Helper functions.
More...
#include "definitions.h"
#include "escape_codes.h"
#include <stdio.h>
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
debugging macros
Definition at line 128 of file helper.h.
custom error stuff
Definition at line 45 of file helper.h.
#define errprintf |
( |
|
... |
) |
|
Value:
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 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 |
#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:
print warning.
Definition at line 143 of file helper.h.
Typedef Documentation
A progressbar-function.
Definition at line 86 of file helper.h.
Function Documentation
int compare_ints |
( |
const void * |
a, |
|
|
const void * |
b | |
|
) |
| | |
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 |
) |
|
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.
Definition at line 92 of file helper.c.
size_t ffwrite |
( |
const void * |
ptr, |
|
|
size_t |
size, |
|
|
size_t |
nmemb, |
|
|
FILE * |
stream | |
|
) |
| | |
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 | |
|
) |
| | |
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 | |
|
) |
| | |
int vprint_vector |
( |
const char * |
name, |
|
|
double * |
v, |
|
|
int |
n | |
|
) |
| | |
void wswap |
( |
void * |
ptr, |
|
|
int |
nmemb, |
|
|
int |
flag | |
|
) |
| | |
Variable Documentation