11 # ifndef WIN32_LEAN_AND_MEAN
12 # define WIN32_LEAN_AND_MEAN
18 #pragma clang diagnostic ignored "-Wmismatched-tags"
37 #define _USE_MATH_DEFINES
45 #if defined(__sun) && defined(__SUNPRO_CC)
68 #include <unordered_map>
72 #if defined(_MSC_VER) && !defined(SYS_CONFIG)
73 #define SYS_CONFIG "cloudyconfig_vs.h"
80 #include "cloudyconfig.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>
121 #define STATIC static
132 #define float PLEASE_USE_REALNUM_NOT_FLOAT
135 inline realnum operator "" _r(
unsigned long long l )
140 inline realnum operator "" _r(
long double l )
145 inline FILE *
sys_fopen(
const char *path,
const char *mode)
147 return fopen( path, mode );
149 #define fopen PLEASE_USE_open_data_NOT_fopen
173 #define EXIT_SUCCESS ES_SUCCESS
175 #define EXIT_FAILURE ES_FAILURE
178 #define lgBOUNDSCHECKVAL true
180 #define lgBOUNDSCHECKVAL false
270 extern long int nzone;
405 double fudge(
long int ipnt);
414 void fixit_base(
const char* func,
const char* file,
int line,
420 Fixit(
const char* func,
const char* file,
int line,
429 static Fixit fixit_s(__func__,__FILE__,__LINE__, (a)); \
442 void MyAssert(
const char *file,
int line,
const char *comment);
465 const char*
file()
const throw()
480 #define cdEXIT( FAIL ) throw cloudy_exit( __func__, __FILE__, __LINE__, FAIL )
483 #define puts( STR ) Using_puts_before_cdEXIT_is_no_longer_needed
510 int dbg_printf(
int debug,
const char *fmt, ...);
513 int dprintf(FILE *fp,
const char *format, ...);
534 #ifdef HAVE_LIBCPP_BUG
539 inline istringstream& operator>> ( istringstream& s,
double& x )
545 inline istringstream& operator>> ( istringstream& s,
sys_float& x )
590 bad_assert(
const char* file,
long line,
const char* comment);
596 fprintf(
ioQQQ,
"DISASTER Assertion failure at %s:%ld\n%s\n",
597 p_file, p_line, p_comment);
599 const char*
file()
const throw()
635 # define ASSERT(exp) ((void)0)
637 # define ASSERT(exp) \
639 if (UNLIKELY(!(exp))) \
640 throw bad_assert(__FILE__,__LINE__,"Failed: " #exp); \
644 #define MESSAGE_ASSERT(msg, exp) ASSERT( (msg) ? (exp) : false )
649 throw out_of_range( str );
655 throw domain_error( str );
659 #pragma does_not_return(OUT_OF_RANGE)
666 #define isnan MyIsnan
684 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'>',name);
688 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'<',name);
705 template<
class Trace>
713 Trace::Inst().enter(p_name);
719 Trace::Inst().leave(p_name);
728 #define DEBUG_ENTRY( funcname ) debugtrace<t_debug> DEBUG_ENTRY( funcname )
730 #define DEBUG_ENTRY( funcname ) ((void)0)
736 return static_cast<char>(
tolower( static_cast<int>(c) ) );
740 return static_cast<unsigned char>(
tolower( static_cast<int>(c) ) );
745 return static_cast<char>(
toupper( static_cast<int>(c) ) );
749 return static_cast<unsigned char>(
toupper( static_cast<int>(c) ) );
753 inline char TorF(
bool l ) {
return l ?
'T' :
'F'; }
757 inline bool is_odd(
int j ) {
return (j&1) == 1; }
758 inline bool is_odd(
long j ) {
return (j&1L) == 1L; }
762 inline long nint(
double x ) {
return static_cast<long>( (x < 0.) ? x-0.5 : x+0.5 ); }
766 inline long min(
int a,
long b ) {
long c = a;
return ( (c < b) ? c : b ); }
767 inline long min(
long a,
int b ) {
long c = b;
return ( (a < c) ? a : c ); }
768 inline double min(
sys_float a,
double b ) {
double c = a;
return ( (c < b) ? c : b ); }
769 inline double min(
double a,
sys_float b ) {
double c = b;
return ( (a < c) ? a : c ); }
774 double powi(
double ,
long int );
778 double powpq(
double x,
int p,
int q);
781 #ifndef HAVE_POW_DOUBLE_INT
782 inline double pow(
double x,
int i ) {
return powi( x,
long(i) ); }
785 #ifndef HAVE_POW_DOUBLE_LONG
786 inline double pow(
double x,
long i ) {
return powi( x, i ); }
789 #ifndef HAVE_POW_FLOAT_INT
793 #ifndef HAVE_POW_FLOAT_LONG
797 #ifndef HAVE_POW_FLOAT_DOUBLE
801 #ifndef HAVE_POW_DOUBLE_FLOAT
807 #define MIN2(a,b) min(a,b)
812 #define MIN3(a,b,c) (min(min(a,b),c))
817 #define MIN4(a,b,c,d) (min(min(a,b),min(c,d)))
821 inline long max(
int a,
long b ) {
long c = a;
return ( (c > b) ? c : b ); }
822 inline long max(
long a,
int b ) {
long c = b;
return ( (a > c) ? a : c ); }
823 inline double max(
sys_float a,
double b ) {
double c = a;
return ( (c > b) ? c : b ); }
824 inline double max(
double a,
sys_float b ) {
double c = b;
return ( (a > c) ? a : c ); }
828 #define MAX2(a,b) max(a,b)
833 #define MAX3(a,b,c) (max(max(a,b),c))
838 #define MAX4(a,b,c,d) (max(max(a,b),max(c,d)))
844 memset(vec.data(), 0, vec.size()*
sizeof(T));
854 return ( y < T() ) ? -abs(x) : abs(x);
860 inline int sign3( T x ) {
return ( x < T() ) ? -1 : ( ( x > T() ) ? 1 : 0 ); }
873 if( sx == 0 && sy == 0 )
882 (void)frexp(
max(x,y), &exp);
883 sys_float epsilon = ldexp(FLT_EPSILON,
max(0,FLT_MIN_EXP-exp));
887 inline bool fp_equal(
double x,
double y,
int n=3 )
896 if( sx == 0 && sy == 0 )
905 (void)frexp(
max(x,y), &exp);
906 double epsilon = ldexp(DBL_EPSILON,
max(0,DBL_MIN_EXP-exp));
907 return ( 1. -
min(x,y)/
max(x,y) < ((
double)n+0.1)*epsilon );
917 ASSERT( tol >= FLT_EPSILON*
max(abs(x),abs(y)) );
918 return ( abs( x-y ) <= tol );
928 ASSERT( tol >= DBL_EPSILON*
max(abs(x),abs(y)) );
929 return ( abs( x-y ) <= tol );
941 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
sys_float)n+0.1f)*FLT_EPSILON )
945 inline bool fp_bound(
double lo,
double x,
double hi,
int n=3 )
953 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
double)n+0.1)*DBL_EPSILON )
965 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
977 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
987 inline T
pow2(T a) {
return a*a; }
994 inline T
pow3(T a) {
return a*a*a; }
1001 inline T
pow4(T a) { T b = a*a;
return b*b; }
1010 inline double SDIV(
double x ) {
return ( fabs(x) < (
double)
SMALLFLOAT ) ? (double)SMALLFLOAT : x; }
1025 if( sx == 0 && sy == 0 )
1027 if(
isnan(res_0by0) )
1035 return ( sx < 0 ) ? -FLT_MAX : FLT_MAX;
1043 if( abs(x) < ay*FLT_MAX )
1046 return ( sx*sy < 0 ) ? -FLT_MAX : FLT_MAX;
1052 return safe_div( x, y, numeric_limits<sys_float>::quiet_NaN() );
1058 inline double safe_div(
double x,
double y,
double res_0by0)
1066 if( sx == 0 && sy == 0 )
1068 if(
isnan(res_0by0) )
1076 return ( sx < 0 ) ? -DBL_MAX : DBL_MAX;
1084 if( abs(x) < ay*DBL_MAX )
1087 return ( sx*sy < 0 ) ? -DBL_MAX : DBL_MAX;
1093 return safe_div( x, y, numeric_limits<double>::quiet_NaN() );
1100 memset( p, -1, size );
1105 set_NaN( p, (
long)(size/
sizeof(
double)) );
1119 template<
class T>
inline T*
get_ptr(valarray<T> &v)
1123 template<
class T,
class U>
inline T*
get_ptr(vector<T,U> &v)
1127 template<
class T>
inline const T*
get_ptr(
const valarray<T> &v)
1129 return const_cast<const T*
>(&
const_cast<valarray<T>&
>(v)[0]);
1131 template<
class T,
class U>
inline const T*
get_ptr(
const vector<T,U> &v)
1133 return const_cast<const T*
>(&
const_cast<vector<T,U>&
>(v)[0]);
1141 double csphot(
long int inu,
long int ithr,
long int iofset);
1150 void cap4(
char *chCAP ,
const char *chLab);
1154 void uncaps(
char *chCard);
1155 void uncaps(
string& chCard);
1159 void caps(
char *chCard);
1160 void caps(
string& chCard);
1168 double FFmtRead(
const char *chCard,
1178 long nMatch(
const char *chKey,
1179 const char *chCard);
1182 inline const char *
strstr_s(
const char *haystack,
const char *needle)
1184 return const_cast<const char *
>(strstr(haystack, needle));
1187 inline char *
strstr_s(
char *haystack,
const char *needle)
1189 return const_cast<char *
>(strstr(haystack, needle));
1194 return const_cast<const char *
>(strchr(s, c));
1199 return const_cast<char *
>(strchr(s, c));
1204 long int ipow(
long,
long );
1208 size_t sncatf(
char* buf,
size_t bufSize,
const char* fmt, ... );
1210 size_t sncatf( ostringstream& buf,
const char* fmt, ... );
1229 char *
PrintEfmt(
const char *fmt,
double val );
1231 #define PrintEfmt( F, V ) F, V
1241 double sexp(
double x);
1247 double dsexp(
double x);
1258 double y = trunc(x/3.);
1261 x *= 2.302585092994045684;
1262 x -= 7.90550887243868070612e-3*z;
1263 return ldexp(exp(x),10*
int(y));
1280 x -= 7.9055088724e-3f*z;
1281 return ldexpf(expf(x),10*
int(y));
1294 double plankf(
long int ip);
1308 void spsort(
realnum x[],
long int n,
long int iperm[],
int kflag,
int *ier);
1319 # pragma warning( disable : 4996 )
1321 # pragma warning( disable : 4056 )
1323 # pragma warning( disable : 4514 )
1326 # pragma warning( disable : 4512 )
1328 #ifdef __INTEL_COMPILER
1329 # pragma warning( disable : 1572 )
const char * p_name
Definition: cddefines.h:708
T pow4(T a)
Definition: cddefines.h:1001
bool lgTestCodeCalled
Definition: cddefines.cpp:10
FILE * ioMAP
Definition: cdinit.cpp:9
void leave(const char *name)
Definition: cddefines.h:686
const char * file() const
Definition: cddefines.h:599
const int ipBERYLLIUM
Definition: cddefines.h:362
void leave(const char *) const
Definition: cddefines.h:702
FILE * p_fp
Definition: cddefines.h:673
t_debug()
Definition: cddefines.h:676
void PrintE93(FILE *, double)
Definition: service.cpp:1126
const int ipMAGNESIUM
Definition: cddefines.h:370
int p_callLevel
Definition: cddefines.h:674
bool is_odd(int j)
Definition: cddefines.h:757
Definition: cddefines.h:447
Definition: cddefines.h:417
virtual ~bad_signal()
Definition: cddefines.h:577
exit_type exit_status() const
Definition: cddefines.h:473
double exp10(double x)
Definition: cddefines.h:1250
const int FILENAME_PATH_LENGTH_2
Definition: cddefines.h:306
#define NORETURN
Definition: cpu.h:461
Definition: cddefines.h:213
istream & SafeGetline(istream &is, string &t)
Definition: service.cpp:1849
FILE * ioStdin
Definition: cddefines.cpp:8
T * get_ptr(T *v)
Definition: cddefines.h:1115
void cdBacktrace()
Definition: cddefines.h:516
NORETURN void TotalInsanity(void)
Definition: service.cpp:1174
const double BIGDOUBLE
Definition: cpu.h:238
bool read_whole_line(string &chLine, FILE *ioIN)
Definition: service.cpp:68
void set_NaN(sys_float &x)
Definition: cpu.cpp:871
const int ipARGON
Definition: cddefines.h:376
const int ipTITANIUM
Definition: cddefines.h:380
const char * file() const
Definition: cddefines.h:465
const realnum SMALLFLOAT
Definition: cpu.h:235
~debugtrace()
Definition: cddefines.h:717
t_cpu_i & i()
Definition: cpu.h:414
FILE * sys_fopen(const char *path, const char *mode)
Definition: cddefines.h:145
const int NISO
Definition: cddefines.h:321
size_t sncatf(char *buf, size_t bufSize, const char *fmt,...)
Definition: service.cpp:919
const char * routine() const
Definition: cddefines.h:461
Definition: cddefines.h:160
FILE * ioPrnErr
Definition: cddefines.cpp:9
char TorF(bool l)
Definition: cddefines.h:753
const int ipOXYGEN
Definition: cddefines.h:366
const int ipCHLORINE
Definition: cddefines.h:375
#define PrintEfmt(F, V)
Definition: cddefines.h:1231
void enter(const char *) const
Definition: cddefines.h:701
long int nzone
Definition: cddefines.cpp:13
void invalidate_array(T *p, size_t size)
Definition: cddefines.h:1097
long nMatch(const char *chKey, const char *chCard)
Definition: service.cpp:728
Definition: cddefines.h:706
const void * ZeroPtr
Definition: cdinit.cpp:15
T sign(T x, T y)
Definition: cddefines.h:852
int sig() const
Definition: cddefines.h:578
const char * name() const
Definition: cddefines.h:721
bool fp_equal_tol(sys_float x, sys_float y, sys_float tol)
Definition: cddefines.h:910
T TotalInsanityAsStub()
Definition: cddefines.h:495
const char * strstr_s(const char *haystack, const char *needle)
Definition: cddefines.h:1182
void GenerateBacktrace(void *ptr)
Definition: cpu.cpp:1178
sys_float sexp(sys_float x)
Definition: service.cpp:1203
const int ipRecNetEsc
Definition: cddefines.h:341
long line() const
Definition: cddefines.h:603
int dbg_printf(int debug, const char *fmt,...)
Definition: service.cpp:1357
T pow3(T a)
Definition: cddefines.h:994
double fudge(long int ipnt)
Definition: service.cpp:758
const int ipCOBALT
Definition: cddefines.h:385
int p_sig
Definition: cddefines.h:572
NORETURN void OUT_OF_RANGE(const char *str)
Definition: cddefines.h:646
bool lgTestCodeEnabled
Definition: cddefines.cpp:11
const int ipNICKEL
Definition: cddefines.h:386
void FPRead(istringstream &iss, const string &s, double &value)
Definition: service.cpp:548
const int ipZINC
Definition: cddefines.h:388
exit_type
Definition: cddefines.h:151
void cap4(char *chCAP, const char *chLab)
Definition: service.cpp:257
Output(FILE *fp)
Definition: cddefines.h:239
const char * p_file
Definition: cddefines.h:586
double dsexp(double x)
Definition: service.cpp:1242
void CodeReview(void)
Definition: service.cpp:1297
const int ipSULPHUR
Definition: cddefines.h:374
Definition: cddefines.h:155
Definition: cddefines.h:164
bool fp_bound_tol(sys_float lo, sys_float x, sys_float hi, sys_float tol)
Definition: cddefines.h:957
void fixit_base(const char *func, const char *file, int line, const char *reason)
Definition: service.cpp:1280
const double MAX_DENSITY
Definition: cddefines.h:329
Definition: cddefines.h:335
Definition: cddefines.h:234
static T & Inst()
Definition: cddefines.h:216
bool lgPrnErr
Definition: cddefines.cpp:12
Definition: cddefines.h:158
void uncaps(char *chCard)
Definition: service.cpp:277
char toupper(char c)
Definition: cddefines.h:743
void print(void) const
Definition: cddefines.h:594
#define fopen
Definition: cddefines.h:149
const double DSEXP_LIMIT
Definition: cddefines.h:1237
void PrintBacktrace(const string &s, bool lgPrintSeed=true)
Definition: cpu.cpp:1185
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:864
void broken(void)
Definition: service.cpp:1271
debugtrace(const char *funcname)
Definition: cddefines.h:710
int dprintf(FILE *fp, const char *format,...)
Definition: service.cpp:1306
const int ipVANADIUM
Definition: cddefines.h:381
const int ipIRON
Definition: cddefines.h:384
void PrintE71(FILE *, double)
Definition: service.cpp:1076
Definition: cddefines.h:156
sys_float exp10f(sys_float x)
Definition: cddefines.h:1268
char tolower(char c)
Definition: cddefines.h:734
double energy(const genericState &gs)
Definition: generic_state.cpp:51
Definition: cddefines.h:159
const char * p_routine
Definition: cddefines.h:449
Definition: cddefines.h:152
const int ipSCANDIUM
Definition: cddefines.h:379
Definition: cddefines.h:695
Fixit(const char *func, const char *file, int line, const char *reason)
Definition: cddefines.h:420
const char * p_comment
Definition: cddefines.h:615
long int iteration
Definition: cddefines.cpp:15
const double ZeroNum
Definition: cdinit.cpp:13
const int ipCRD
Definition: cddefines.h:352
void enter(const char *name)
Definition: cddefines.h:681
FILE * m_fp
Definition: cddefines.h:237
virtual ~bad_assert()
Definition: cddefines.h:593
long p_line
Definition: cddefines.h:451
float realnum
Definition: cddefines.h:127
float sys_float
Definition: cddefines.h:130
const int ipLY_A
Definition: cddefines.h:356
const realnum BIGFLOAT
Definition: cpu.h:233
const int ipPHOSPHORUS
Definition: cddefines.h:373
const int INPUT_LINE_LENGTH
Definition: cddefines.h:311
long max(int a, long b)
Definition: cddefines.h:821
NORETURN void DOMAIN_ERROR(const string &str)
Definition: cddefines.h:652
int sign3(T x)
Definition: cddefines.h:860
const char * p_file
Definition: cddefines.h:450
const int ipNEON
Definition: cddefines.h:368
const int ipCHROMIUM
Definition: cddefines.h:382
double powi(double, long int)
Definition: service.cpp:797
const int ipRecRad
Definition: cddefines.h:343
long min(int a, long b)
Definition: cddefines.h:766
bool fp_bound(sys_float lo, sys_float x, sys_float hi, int n=3)
Definition: cddefines.h:933
long p_line
Definition: cddefines.h:587
const char * strchr_s(const char *s, int c)
Definition: cddefines.h:1192
sys_float safe_div(sys_float x, sys_float y, sys_float res_0by0)
Definition: cddefines.h:1017
const int ipRecEsc
Definition: cddefines.h:339
virtual ~cloudy_abort()
Definition: cddefines.h:620
#define NULL
Definition: cddefines.h:115
Definition: cddefines.h:154
Definition: cddefines.h:166
exit_type p_exit
Definition: cddefines.h:452
const int ipKRYPTON
Definition: cddefines.h:389
double AnuUnit(realnum energy)
Definition: service.cpp:189
void MyAssert(const char *file, int line, const char *comment)
Definition: service.cpp:172
Definition: cddefines.h:334
FILE * ioQQQ
Definition: cddefines.cpp:7
const int ipSILICON
Definition: cddefines.h:372
const char * comment() const
Definition: cddefines.h:607
long int ipow(long, long)
Definition: service.cpp:861
#define ASSERT(exp)
Definition: cddefines.h:637
FILE * fptr() const
Definition: cddefines.h:240
const int ipALUMINIUM
Definition: cddefines.h:371
const char * p_comment
Definition: cddefines.h:588
const int ipCALCIUM
Definition: cddefines.h:378
const int ipNITROGEN
Definition: cddefines.h:365
double csphot(long int inu, long int ithr, long int iofset)
Definition: service.cpp:1768
const int LIMELM
Definition: cddefines.h:318
T pow2(T a)
Definition: cddefines.h:987
const int ipFLUORINE
Definition: cddefines.h:367
double powpq(double x, int p, int q)
Definition: service.cpp:833
#define isnan
Definition: cddefines.h:666
const int ipHELIUM
Definition: cddefines.h:360
Definition: cddefines.h:163
const int ipMANGANESE
Definition: cddefines.h:383
const char * comment() const
Definition: cddefines.h:621
double fnzone
Definition: cddefines.cpp:14
long line() const
Definition: cddefines.h:469
Definition: cddefines.h:584
void vzero(vector< T > &vec)
Definition: cddefines.h:842
Definition: cddefines.h:157
const int NCHLAB
Definition: cddefines.h:314
const int FILENAME_PATH_LENGTH
Definition: cddefines.h:303
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1325
Definition: cddefines.h:570
Definition: cddefines.h:613
Definition: cddefines.h:161
Definition: cddefines.h:162
const int ipPRD
Definition: cddefines.h:350
sys_float SDIV(sys_float x)
Definition: cddefines.h:1008
double pow(double x, int i)
Definition: cddefines.h:782
const int ipCARBON
Definition: cddefines.h:364
cloudy_exit(const char *routine, const char *file, long line, exit_type exit_code)
Definition: cddefines.h:454
long nint(double x)
Definition: cddefines.h:762
void caps(char *chCard)
Definition: service.cpp:299
static t_cpu cpu
Definition: cpu.h:422
void ShowMe(void)
Definition: service.cpp:197
void PrintE82(FILE *, double)
Definition: service.cpp:1027
Definition: cddefines.h:670
const double SEXP_LIMIT
Definition: cddefines.h:1235
Definition: cddefines.h:165
double plankf(long int ip)
Definition: service.cpp:1786
const int ipHYDROGEN
Definition: cddefines.h:359
const int ipLITHIUM
Definition: cddefines.h:361
void cdPrepareExit(exit_type)
Definition: cdinit.cpp:131
const double DEPTH_OFFSET
Definition: cddefines.h:332
void TestCode(void)
Definition: service.cpp:1261
Definition: cddefines.h:167
const int ipPOTASSIUM
Definition: cddefines.h:377
const int NHYDRO_MAX_LEVEL
Definition: cddefines.h:326
NORETURN void BadRead(void)
Definition: service.cpp:1190
const int ipBORON
Definition: cddefines.h:363
const int ipCRDW
Definition: cddefines.h:354
const int ipSODIUM
Definition: cddefines.h:369
Definition: cddefines.h:153
void spsort(realnum x[], long int n, long int iperm[], int kflag, int *ier)
Definition: service.cpp:1426
t_nodebug()
Definition: cddefines.h:699
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
Definition: service.cpp:393
const int ipCOPPER
Definition: cddefines.h:387