11 # pragma warning( disable : 4127 )
13 # ifndef WIN32_LEAN_AND_MEAN
14 # define WIN32_LEAN_AND_MEAN
20 #pragma clang diagnostic ignored "-Wmismatched-tags"
39 #define _USE_MATH_DEFINES
47 #if defined(__sun) && defined(__SUNPRO_CC)
72 #if defined(_MSC_VER) && !defined(SYS_CONFIG)
73 #define SYS_CONFIG "cloudyconfig_vs.h"
84 #ifndef HAVE_AVX_INTRIN
88 #ifndef HAVE_FMA_INTRIN
92 #ifndef HAVE_AVX2_INTRIN
96 #ifndef HAVE_AVX512F_INTRIN
101 #include <immintrin.h>
118 #define STATIC static
129 #define float PLEASE_USE_REALNUM_NOT_FLOAT
131 inline FILE *
sys_fopen(
const char *path,
const char *mode)
133 return fopen( path, mode );
135 #define fopen PLEASE_USE_open_data_NOT_fopen
140 #define STATIC_ASSERT(x) ((void)StaticAssertFailed< (x) == true >())
166 #define EXIT_SUCCESS ES_SUCCESS
168 #define EXIT_FAILURE ES_FAILURE
171 #define lgBOUNDSCHECKVAL true
173 #define lgBOUNDSCHECKVAL false
266 extern long int nzone;
395 double fudge(
long int ipnt);
404 void fixit_base(
const char* func,
const char* file,
int line,
410 Fixit(
const char* func,
const char* file,
int line,
419 static Fixit fixit_s(__func__,__FILE__,__LINE__, (a)); \
433 void *
MyMalloc(
size_t size,
const char *file,
int line);
439 void MyAssert(
const char *file,
int line,
const char *comment);
467 const char*
file()
const throw()
482 #define cdEXIT( FAIL ) throw cloudy_exit( __func__, __FILE__, __LINE__, FAIL )
485 #define puts( STR ) Using_puts_before_cdEXIT_is_no_longer_needed
512 int dbg_printf(
int debug,
const char *fmt, ...);
515 int dprintf(FILE *fp,
const char *format, ...);
551 # define MALLOC(exp) (malloc(exp))
554 # define MALLOC(exp) (MyMalloc(exp, __FILE__, __LINE__))
578 bad_assert(
const char* file,
long line,
const char* comment);
581 fprintf(
ioQQQ,
"DISASTER Assertion failure at %s:%ld\n%s\n",
582 p_file, p_line, p_comment);
588 const char*
file()
const throw()
611 # define ASSERT(exp) ((void)0)
613 # define ASSERT(exp) \
615 if (UNLIKELY(!(exp))) \
617 bad_assert aa(__FILE__,__LINE__,"Failed: " #exp); \
618 if( cpu.i().lgAssertAbort() ) \
631 # define ASSERT(exp) ((void)0)
633 # define ASSERT(exp) \
636 MyAssert(__FILE__, __LINE__, "Failed: " #exp); \
641 #define MESSAGE_ASSERT(msg, exp) ASSERT( (msg) ? (exp) : false )
648 throw out_of_range( str );
652 #pragma does_not_return(OUT_OF_RANGE)
659 #define isnan MyIsnan
677 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'>',name);
681 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'<',name);
698 template<
class Trace>
706 Trace::Inst().enter(p_name);
710 Trace::Inst().leave(p_name);
720 #define DEBUG_ENTRY( funcname ) debugtrace<t_debug> DEBUG_ENTRY( funcname )
723 #define DEBUG_ENTRY( funcname ) ((void)0)
725 #define DEBUG_ENTRY( funcname ) debugtrace<t_nodebug> DEBUG_ENTRY( funcname )
732 return static_cast<char>(
tolower( static_cast<int>(c) ) );
736 return static_cast<unsigned char>(
tolower( static_cast<int>(c) ) );
741 return static_cast<char>(
toupper( static_cast<int>(c) ) );
745 return static_cast<unsigned char>(
toupper( static_cast<int>(c) ) );
749 inline char TorF(
bool l ) {
return l ?
'T' :
'F'; }
753 inline bool is_odd(
int j ) {
return (j&1) == 1; }
754 inline bool is_odd(
long j ) {
return (j&1L) == 1L; }
758 inline long nint(
double x ) {
return static_cast<long>( (x < 0.) ? x-0.5 : x+0.5 ); }
762 inline long min(
int a,
long b ) {
long c = a;
return ( (c < b) ? c : b ); }
763 inline long min(
long a,
int b ) {
long c = b;
return ( (a < c) ? a : c ); }
764 inline double min(
sys_float a,
double b ) {
double c = a;
return ( (c < b) ? c : b ); }
765 inline double min(
double a,
sys_float b ) {
double c = b;
return ( (a < c) ? a : c ); }
770 double powi(
double ,
long int );
774 double powpq(
double x,
int p,
int q);
777 #ifndef HAVE_POW_DOUBLE_INT
778 inline double pow(
double x,
int i ) {
return powi( x,
long(i) ); }
781 #ifndef HAVE_POW_DOUBLE_LONG
782 inline double pow(
double x,
long i ) {
return powi( x, i ); }
785 #ifndef HAVE_POW_FLOAT_INT
789 #ifndef HAVE_POW_FLOAT_LONG
793 #ifndef HAVE_POW_FLOAT_DOUBLE
794 inline double pow(
sys_float x,
double y ) {
return pow(
double(x), y ); }
797 #ifndef HAVE_POW_DOUBLE_FLOAT
798 inline double pow(
double x,
sys_float y ) {
return pow( x,
double(y) ); }
803 #define MIN2(a,b) min(a,b)
808 #define MIN3(a,b,c) (min(min(a,b),c))
813 #define MIN4(a,b,c,d) (min(min(a,b),min(c,d)))
817 inline long max(
int a,
long b ) {
long c = a;
return ( (c > b) ? c : b ); }
818 inline long max(
long a,
int b ) {
long c = b;
return ( (a > c) ? a : c ); }
819 inline double max(
sys_float a,
double b ) {
double c = a;
return ( (c > b) ? c : b ); }
820 inline double max(
double a,
sys_float b ) {
double c = b;
return ( (a > c) ? a : c ); }
824 #define MAX2(a,b) max(a,b)
829 #define MAX3(a,b,c) (max(max(a,b),c))
834 #define MAX4(a,b,c,d) (max(max(a,b),max(c,d)))
844 return ( y < T() ) ? -abs(x) : abs(x);
850 inline int sign3( T x ) {
return ( x < T() ) ? -1 : ( ( x > T() ) ? 1 : 0 ); }
858 # pragma warning( disable : 4127 )
867 if( sx == 0 && sy == 0 )
876 (void)frexp(
max(x,y), &exp);
877 sys_float epsilon = ldexp(FLT_EPSILON,
max(0,FLT_MIN_EXP-exp));
881 inline bool fp_equal(
double x,
double y,
int n=3 )
890 if( sx == 0 && sy == 0 )
899 (void)frexp(
max(x,y), &exp);
900 double epsilon = ldexp(DBL_EPSILON,
max(0,DBL_MIN_EXP-exp));
901 return ( 1. -
min(x,y)/
max(x,y) < ((
double)n+0.1)*epsilon );
911 ASSERT( tol >= FLT_EPSILON*
max(abs(x),abs(y)) );
912 return ( abs( x-y ) <= tol );
922 ASSERT( tol >= DBL_EPSILON*
max(abs(x),abs(y)) );
923 return ( abs( x-y ) <= tol );
935 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
sys_float)n+0.1f)*FLT_EPSILON )
939 inline bool fp_bound(
double lo,
double x,
double hi,
int n=3 )
947 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
double)n+0.1)*DBL_EPSILON )
959 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
971 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
981 inline T
pow2(T a) {
return a*a; }
988 inline T
pow3(T a) {
return a*a*a; }
995 inline T
pow4(T a) { T b = a*a;
return b*b; }
1004 inline double SDIV(
double x ) {
return ( fabs(x) < (
double)
SMALLFLOAT ) ? (double)SMALLFLOAT : x; }
1019 if( sx == 0 && sy == 0 )
1021 if(
isnan(res_0by0) )
1029 return ( sx < 0 ) ? -FLT_MAX : FLT_MAX;
1037 if( abs(x) < ay*FLT_MAX )
1040 return ( sx*sy < 0 ) ? -FLT_MAX : FLT_MAX;
1046 return safe_div( x, y, numeric_limits<sys_float>::quiet_NaN() );
1052 inline double safe_div(
double x,
double y,
double res_0by0)
1060 if( sx == 0 && sy == 0 )
1062 if(
isnan(res_0by0) )
1070 return ( sx < 0 ) ? -DBL_MAX : DBL_MAX;
1078 if( abs(x) < ay*DBL_MAX )
1081 return ( sx*sy < 0 ) ? -DBL_MAX : DBL_MAX;
1087 return safe_div( x, y, numeric_limits<double>::quiet_NaN() );
1094 memset( p, -1, size );
1099 set_NaN( p, (
long)(size/
sizeof(
double)) );
1113 template<
class T>
inline T*
get_ptr(valarray<T> &v)
1117 template<
class T,
class U>
inline T*
get_ptr(vector<T,U> &v)
1121 template<
class T>
inline const T*
get_ptr(
const valarray<T> &v)
1123 return const_cast<const T*
>(&
const_cast<valarray<T>&
>(v)[0]);
1125 template<
class T,
class U>
inline const T*
get_ptr(
const vector<T,U> &v)
1127 return const_cast<const T*
>(&
const_cast<vector<T,U>&
>(v)[0]);
1186 reset( p.release() );
1250 double csphot(
long int inu,
long int ithr,
long int iofset);
1256 double RandGauss(
double xMean,
double s );
1270 void cap4(
char *chCAP ,
const char *chLab);
1274 void uncaps(
char *chCard );
1278 void caps(
char *chCard );
1286 double FFmtRead(
const char *chCard,
1296 long nMatch(
const char *chKey,
1297 const char *chCard);
1300 inline const char *
strstr_s(
const char *haystack,
const char *needle)
1302 return const_cast<const char *
>(strstr(haystack, needle));
1305 inline char *
strstr_s(
char *haystack,
const char *needle)
1307 return const_cast<char *
>(strstr(haystack, needle));
1312 return const_cast<const char *
>(strchr(s, c));
1317 return const_cast<char *
>(strchr(s, c));
1322 long int ipow(
long,
long );
1326 size_t sncatf(
char* buf,
size_t bufSize,
const char* fmt, ... );
1328 size_t sncatf( ostringstream& buf,
const char* fmt, ... );
1347 char *
PrintEfmt(
const char *fmt,
double val );
1349 #define PrintEfmt( F, V ) F, V
1359 double sexp(
double x);
1365 double dsexp(
double x);
1376 double y = trunc(x/3.);
1379 x *= 2.302585092994045684;
1380 x -= 7.90550887243868070612e-3*z;
1381 return ldexp(exp(x),10*
int(y));
1398 x -= 7.9055088724e-3f*z;
1399 return ldexpf(expf(x),10*
int(y));
1412 double plankf(
long int ip);
1426 void spsort(
realnum x[],
long int n,
long int iperm[],
int kflag,
int *ier);
1437 # pragma warning( disable : 4127 )
1439 # pragma warning( disable : 4996 )
1441 # pragma warning( disable : 4056 )
1443 # pragma warning( disable : 4514 )
1446 # pragma warning( disable : 4512 )
1448 #ifdef __INTEL_COMPILER
1449 # pragma warning( disable : 1572 )
void leave(const char *name)
const char * file() const
void leave(const char *) const
void PrintE93(FILE *, double)
exit_type exit_status() const
const int FILENAME_PATH_LENGTH_2
istream & SafeGetline(istream &is, string &t)
NORETURN void TotalInsanity(void)
void set_NaN(sys_float &x)
const char * file() const
FILE * sys_fopen(const char *path, const char *mode)
size_t sncatf(char *buf, size_t bufSize, const char *fmt,...)
const char * routine() const
void enter(const char *) const
void invalidate_array(T *p, size_t size)
long nMatch(const char *chKey, const char *chCard)
const char * name() const
bool fp_equal_tol(sys_float x, sys_float y, sys_float tol)
const char * strstr_s(const char *haystack, const char *needle)
void * MyMalloc(size_t size, const char *file, int line)
sys_float sexp(sys_float x)
int dbg_printf(int debug, const char *fmt,...)
double fudge(long int ipnt)
NORETURN void OUT_OF_RANGE(const char *str)
void cap4(char *chCAP, const char *chLab)
bool fp_bound_tol(sys_float lo, sys_float x, sys_float hi, sys_float tol)
void fixit_base(const char *func, const char *file, int line, const char *reason)
bool lgAssertAbort() const
void uncaps(char *chCard)
element_type * data() const
bool fp_equal(sys_float x, sys_float y, int n=3)
debugtrace(const char *funcname)
int dprintf(FILE *fp, const char *format,...)
void PrintE71(FILE *, double)
sys_float exp10f(sys_float x)
double energy(const genericState &gs)
auto_vec(element_type *p=NULL)
Fixit(const char *func, const char *file, int line, const char *reason)
void enter(const char *name)
const int INPUT_LINE_LENGTH
double powi(double, long int)
bool fp_bound(sys_float lo, sys_float x, sys_float hi, int n=3)
const char * strchr_s(const char *s, int c)
sys_float safe_div(sys_float x, sys_float y, sys_float res_0by0)
double RandGauss(double xMean, double s)
void reset(element_type *p=NULL)
double AnuUnit(realnum energy)
void MyAssert(const char *file, int line, const char *comment)
const char * comment() const
long int ipow(long, long)
double csphot(long int inu, long int ithr, long int iofset)
auto_vec(auto_vec_ref< element_type > r)
double powpq(double x, int p, int q)
const int FILENAME_PATH_LENGTH
int fprintf(const Output &stream, const char *format,...)
sys_float SDIV(sys_float x)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
cloudy_exit(const char *routine, const char *file, long line, exit_type exit_code)
double MyGaussRand(double PctUncertainty)
void PrintE82(FILE *, double)
double plankf(long int ip)
void cdPrepareExit(exit_type)
const double DEPTH_OFFSET
const int NHYDRO_MAX_LEVEL
NORETURN void BadRead(void)
void spsort(realnum x[], long int n, long int iperm[], int kflag, int *ier)
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)