MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
common.h File Reference

Macros

#define MAX(a, b)
#define MIN(a, b)
#define RSS(a, b)
#define CLIP(x, d_, u_)
#define restrict   __restrict
#define EPS   1.e-15
#define BASEFILE   mybasename(__FILE__)
#define BLACK   "\033[00;00m"
#define RED   "\033[01;31m"
#define GREEN   "\033[0;32m"
#define YELLOW   "\033[0;33m"
#define BLUE   "\033[0;34m"
#define MAGENTA   "\033[0;35m"
#define CYAN   "\033[0;36m"
#define logstd(level, A...)
#define logerr(level, COLOR, format, ...)
#define logdbg(level, COLOR, format, ...)
#define error(format, ...)
#define warning(format, ...)
#define warning_time(format, ...)
#define warning_once(A...)
#define info_line(format, ...)
#define info_time(format, ...)
#define info_green(A...)
#define info(A...)
#define info2(A...)
#define info3(A...)
#define info_once(A...)
#define info_progress(i, n)
#define info_errno(A)
#define dbg(A...)
#define dbg2(A...)
#define dbg3(A...)
#define logdbg_time(level, format, ...)
#define dbg_line(format, ...)
#define dbg_time(A...)
#define dbg2_time(A...)
#define dbg3_time(A...)
#define dbg_once(A...)
#define assert(A)
#define check(A)
#define TIC   double tk
#define tic   tk=myclockd()
#define toc(format, ...)
#define toc2(format, ...)
#define toc3   (myclockd()-tk)
#define format2fn
#define CHECK_ARG(n)
#define LIKELY(A)
#define UNLIKELY(A)
#define CHECK_UNUSED_RESULT
#define CHECK_NULL_TERMINATED
#define STR_TO_INT(A, B)
#define STR_TO_DBL(A, B)
#define READ_ENV_NUM(A, min, max, T, FUN)
#define READ_ENV_INT(A, min, max)
#define READ_ENV_DBL(A, min, max)
#define DEF_ENV_FLAG(A, default_val)
#define FREE(A)

Detailed Description

Every source file in this folder should include this file

Macro Definition Documentation

◆ MAX

#define MAX ( a,
b )
Value:
({__typeof__(a) _M1=(a); __typeof__(b) _M2=(b); (_M1)>(_M2)?(_M1):(_M2);})

◆ MIN

#define MIN ( a,
b )
Value:
({__typeof__(a) _m1=(a); __typeof__(b) _m2=(b); (_m1)<(_m2)?(_m1):(_m2);})

◆ RSS

#define RSS ( a,
b )
Value:
({__typeof__(a) _M1=(a); __typeof__(b) _M2=(b); sqrtf(_M1*_M1+_M2*_M2);})

◆ CLIP

#define CLIP ( x,
d_,
u_ )
Value:
({__typeof__(d_) d=(d_); __typeof__(u_) u=(u_);x=x<d?d:(x>u?u:x);})

◆ logstd

#define logstd ( level,
A... )
Value:
({if(LOG_LEVEL>level){if(!detached)fprintf(stdout, A); if(fplog){fprintf(fplog, A);}}})

◆ logerr

#define logerr ( level,
COLOR,
format,
... )
Value:
({if(LOG_LEVEL>level){if(!detached)fprintf(stderr, COLOR format BLACK, ##__VA_ARGS__); if(fplog){fprintf(fplog, format, ##__VA_ARGS__);}}})

◆ logdbg

#define logdbg ( level,
COLOR,
format,
... )
Value:
({if(LOG_LEVEL>level){if(!detached)fprintf(stdout, COLOR format BLACK, ##__VA_ARGS__); if(fplog){fprintf(fplog, format, ##__VA_ARGS__);}}})

◆ error

#define error ( format,
... )
Value:
({logerr(-4, RED, "Error(%s:%d): " format, BASEFILE,__LINE__, ##__VA_ARGS__); raise(SIGUSR2);})

◆ warning

#define warning ( format,
... )
Value:
logerr(-4, CYAN, "Warning(%s:%d): " format, BASEFILE,__LINE__, ##__VA_ARGS__)

◆ warning_time

#define warning_time ( format,
... )
Value:
logerr(-4, CYAN, "[%s] Warning(%s:%d): " format, myasctime(0),BASEFILE,__LINE__, ##__VA_ARGS__)

◆ warning_once

#define warning_once ( A...)
Value:
({static int done=0; if(!done){done=1; warning(A);}})

◆ info_line

#define info_line ( format,
... )
Value:
logstd(-4, "Info(%s:%d): " format, BASEFILE,__LINE__,##__VA_ARGS__)

◆ info_time

#define info_time ( format,
... )
Value:
logstd(-1, "[%s] Info(%s:%d): " format, myasctime(0), BASEFILE,__LINE__,##__VA_ARGS__)

◆ info_green

#define info_green ( A...)
Value:
logdbg(-2, GREEN, A)

◆ info

#define info ( A...)
Value:
logstd(-1, A)

◆ info2

#define info2 ( A...)
Value:
logstd(-2, A)

◆ info3

#define info3 ( A...)
Value:
logstd(-3, A)

◆ info_once

#define info_once ( A...)
Value:
({static int done=0; if(!done){done=1; info(A);}})

◆ info_progress

#define info_progress ( i,
n )
Value:
if((i)%(((n)>>4)+1)==0) fprintf(stderr,">")

◆ info_errno

#define info_errno ( A)
Value:
if(errno) info(A " failed (%d): %s\n", errno, strerror(errno))

◆ dbg

#define dbg ( A...)
Value:
logdbg(0, YELLOW, A)

◆ dbg2

#define dbg2 ( A...)
Value:
logdbg(1, YELLOW, A)

◆ dbg3

#define dbg3 ( A...)
Value:
logdbg(2, YELLOW, A)

◆ logdbg_time

#define logdbg_time ( level,
format,
... )
Value:
logdbg(level, YELLOW, "[%s] %s: " format, myasctime(0), __func__, ##__VA_ARGS__)

◆ dbg_line

#define dbg_line ( format,
... )
Value:
logdbg(0, YELLOW, "Debug(%s:%d): " format,BASEFILE,__LINE__,##__VA_ARGS__)

◆ dbg_time

#define dbg_time ( A...)
Value:
logdbg_time(0, A)

◆ dbg2_time

#define dbg2_time ( A...)
Value:
logdbg_time(1, A)

◆ dbg3_time

#define dbg3_time ( A...)
Value:
logdbg_time(2, A)

◆ dbg_once

#define dbg_once ( A...)
Value:
({static int done=0; if(!done){done=1; dbg_line(A);}})

◆ check

#define check ( A)
Value:
(A)

◆ toc

#define toc ( format,
... )
Value:
logstd(-1, format " takes %.6f seconds.\n", ##__VA_ARGS__, myclockd()-tk)
double myclockd(void)
Definition misc.c:236

◆ toc2

#define toc2 ( format,
... )
Value:
dbg(format " takes %.6f seconds.\n", ##__VA_ARGS__, myclockd()-tk)

◆ LIKELY

#define LIKELY ( A)
Value:
A

◆ UNLIKELY

#define UNLIKELY ( A)
Value:
A

◆ STR_TO_INT

#define STR_TO_INT ( A,
B )
Value:
strtol(A,B,10)

◆ STR_TO_DBL

#define STR_TO_DBL ( A,
B )
Value:
strtod(A,B)

◆ READ_ENV_INT

#define READ_ENV_INT ( A,
min,
max )
Value:
READ_ENV_NUM(A,min,max,int, STR_TO_INT)

◆ READ_ENV_DBL

#define READ_ENV_DBL ( A,
min,
max )
Value:
READ_ENV_NUM(A,min,max,double,STR_TO_DBL)

◆ DEF_ENV_FLAG

#define DEF_ENV_FLAG ( A,
default_val )
Value:
static int A=default_val; \
static __attribute__((constructor)) void init(){\
READ_ENV_INT(A, 0, INT_MAX);\
}

◆ FREE

#define FREE ( A)
Value:
if(A){free(A); A=NULL;}