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"
101 #define STATIC static
112 #define float PLEASE_USE_REALNUM_NOT_FLOAT
117 #define STATIC_ASSERT(x) ((void)StaticAssertFailed< (x) == true >())
142 #define EXIT_SUCCESS ES_SUCCESS
144 #define EXIT_FAILURE ES_FAILURE
223 extern long int nzone;
355 double fudge(
long int ipnt);
377 void *
MyMalloc(
size_t size,
const char *file,
int line);
383 void *
MyCalloc(
size_t num,
size_t size);
395 void MyAssert(
const char *file,
int line,
const char *comment);
423 const char*
file()
const throw()
438 #define cdEXIT( FAIL ) throw cloudy_exit( __func__, __FILE__, __LINE__, FAIL )
441 #define puts( STR ) Using_puts_before_cdEXIT_is_no_longer_needed
468 int dbg_printf(
int debug,
const char *fmt, ...);
471 int dprintf(FILE *fp,
const char *format, ...);
502 # define MALLOC(exp) (malloc(exp))
505 # define MALLOC(exp) (MyMalloc(exp,__FILE__, __LINE__))
511 # define CALLOC calloc
514 # define CALLOC MyCalloc
520 # define REALLOC realloc
523 # define REALLOC MyRealloc
547 bad_assert(
const char* file,
long line,
const char* comment);
550 fprintf(
ioQQQ,
"DISASTER Assertion failure at %s:%ld\n%s\n",
551 p_file, p_line, p_comment);
557 const char*
file()
const throw()
580 # define ASSERT(exp) ((void)0)
582 # define ASSERT(exp) \
584 if (UNLIKELY(!(exp))) \
586 bad_assert aa(__FILE__,__LINE__,"Failed: " #exp); \
587 if( cpu.i().lgAssertAbort() ) \
600 # define ASSERT(exp) ((void)0)
602 # define ASSERT(exp) \
605 MyAssert(__FILE__, __LINE__, "Failed: " #exp); \
610 #define MESSAGE_ASSERT(msg, exp) ASSERT( (msg) ? (exp) : false )
617 throw out_of_range( str );
624 #define isnan MyIsnan
642 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'>',name);
646 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'<',name);
663 template<
class Trace>
671 Trace::Inst().enter(p_name);
675 Trace::Inst().leave(p_name);
685 #define DEBUG_ENTRY( funcname ) debugtrace<t_debug> DEBUG_ENTRY( funcname )
688 #define DEBUG_ENTRY( funcname ) ((void)0)
690 #define DEBUG_ENTRY( funcname ) debugtrace<t_nodebug> DEBUG_ENTRY( funcname )
697 return static_cast<char>(
tolower( static_cast<int>(c) ) );
701 return static_cast<unsigned char>(
tolower( static_cast<int>(c) ) );
706 return static_cast<char>(
toupper( static_cast<int>(c) ) );
710 return static_cast<unsigned char>(
toupper( static_cast<int>(c) ) );
714 inline char TorF(
bool l ) {
return l ?
'T' :
'F'; }
718 inline bool is_odd(
int j ) {
return (j&1) == 1; }
719 inline bool is_odd(
long j ) {
return (j&1L) == 1L; }
723 inline long nint(
double x ) {
return static_cast<long>( (x < 0.) ? x-0.5 : x+0.5 ); }
727 inline long min(
int a,
long b ) {
long c = a;
return ( (c < b) ? c : b ); }
728 inline long min(
long a,
int b ) {
long c = b;
return ( (a < c) ? a : c ); }
729 inline double min(
sys_float a,
double b ) {
double c = a;
return ( (c < b) ? c : b ); }
730 inline double min(
double a,
sys_float b ) {
double c = b;
return ( (a < c) ? a : c ); }
735 double powi(
double ,
long int );
739 #ifndef HAVE_POW_DOUBLE_INT
740 inline double pow(
double x,
int i ) {
return powi( x,
long(i) ); }
743 #ifndef HAVE_POW_DOUBLE_LONG
744 inline double pow(
double x,
long i ) {
return powi( x, i ); }
747 #ifndef HAVE_POW_FLOAT_INT
751 #ifndef HAVE_POW_FLOAT_LONG
755 #ifndef HAVE_POW_FLOAT_DOUBLE
756 inline double pow(
sys_float x,
double y ) {
return pow(
double(x), y ); }
759 #ifndef HAVE_POW_DOUBLE_FLOAT
760 inline double pow(
double x,
sys_float y ) {
return pow( x,
double(y) ); }
770 #define MIN3(a,b,c) (min(min(a,b),c))
775 #define MIN4(a,b,c,d) (min(min(a,b),min(c,d)))
779 inline long max(
int a,
long b ) {
long c = a;
return ( (c > b) ? c : b ); }
780 inline long max(
long a,
int b ) {
long c = b;
return ( (a > c) ? a : c ); }
781 inline double max(
sys_float a,
double b ) {
double c = a;
return ( (c > b) ? c : b ); }
782 inline double max(
double a,
sys_float b ) {
double c = b;
return ( (a > c) ? a : c ); }
791 #define MAX3(a,b,c) (max(max(a,b),c))
796 #define MAX4(a,b,c,d) (max(max(a,b),max(c,d)))
806 return ( y < T() ) ? -abs(x) : abs(x);
812 inline int sign3( T x ) {
return ( x < T() ) ? -1 : ( ( x > T() ) ? 1 : 0 ); }
820 # pragma warning( disable : 4127 )
829 if( sx == 0 && sy == 0 )
839 inline bool fp_equal(
double x,
double y,
int n=3 )
848 if( sx == 0 && sy == 0 )
855 return ( 1. -
min(x,y)/
max(x,y) < ((
double)n+0.1)*DBL_EPSILON );
865 ASSERT( tol >= FLT_EPSILON*
max(abs(x),abs(y)) );
866 return ( abs( x-y ) <= tol );
876 ASSERT( tol >= DBL_EPSILON*
max(abs(x),abs(y)) );
877 return ( abs( x-y ) <= tol );
889 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
sys_float)n+0.1f)*FLT_EPSILON )
893 inline bool fp_bound(
double lo,
double x,
double hi,
int n=3 )
901 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
double)n+0.1)*DBL_EPSILON )
913 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
925 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
935 inline T
pow2(T a) {
return a*a; }
942 inline T
pow3(T a) {
return a*a*a; }
949 inline T
pow4(T a) { T b = a*a;
return b*b; }
958 inline double SDIV(
double x ) {
return ( fabs(x) < (
double)
SMALLFLOAT ) ? (double)SMALLFLOAT : x; }
973 if( sx == 0 && sy == 0 )
975 if(
isnan(res_0by0) )
983 return ( sx < 0 ) ? -FLT_MAX : FLT_MAX;
991 if( abs(x) < ay*FLT_MAX )
994 return ( sx*sy < 0 ) ? -FLT_MAX : FLT_MAX;
1000 return safe_div( x, y, numeric_limits<sys_float>::quiet_NaN() );
1006 inline double safe_div(
double x,
double y,
double res_0by0)
1014 if( sx == 0 && sy == 0 )
1016 if(
isnan(res_0by0) )
1024 return ( sx < 0 ) ? -DBL_MAX : DBL_MAX;
1032 if( abs(x) < ay*DBL_MAX )
1035 return ( sx*sy < 0 ) ? -DBL_MAX : DBL_MAX;
1041 return safe_div( x, y, numeric_limits<double>::quiet_NaN() );
1050 #define HMRATE(a,b,c) hmrate4(a,b,c,phycon.te)
1052 inline double hmrate4(
double a,
double b,
double c,
double te )
1054 if( b == 0. && c == 0. )
1057 return a*pow(te/300.,b);
1059 return ( c/te <= 50. ) ? a*exp(-c/te) : 0.;
1061 return ( c/te <= 50. ) ? a*pow(te/300.,b)*exp(-c/te) : 0.;
1068 memset( p, -1, size );
1073 set_NaN( p, (
long)(size/
sizeof(
double)) );
1087 template<
class T>
inline T*
get_ptr(valarray<T> &v)
1095 template<
class T>
inline const T*
get_ptr(
const valarray<T> &v)
1097 return const_cast<const T*
>(&
const_cast<valarray<T>&
>(v)[0]);
1099 template<
class T>
inline const T*
get_ptr(
const vector<T> &v)
1101 return const_cast<const T*
>(&
const_cast<vector<T>&
>(v)[0]);
1160 reset( p.release() );
1328 void Split(
const string& str,
1330 vector<string>& lst,
1336 const string& substr,
1337 const string& newstr)
1339 string::size_type ptr = str.find( substr );
1340 if( ptr != string::npos )
1341 str.replace( ptr, substr.length(), newstr );
1342 return ptr != string::npos;
1348 const string& substr)
1358 double csphot(
long int inu,
long int ithr,
long int iofset);
1364 double RandGauss(
double xMean,
double s );
1378 void cap4(
char *chCAP ,
const char *chLab);
1382 void uncaps(
char *chCard );
1386 void caps(
char *chCard );
1395 double ee1(
double x);
1408 double FFmtRead(
const char *chCard,
1418 long nMatch(
const char *chKey,
1419 const char *chCard);
1430 int GetQuote(
char *chLabel,
char *chCard,
char *chCardRaw,
bool lgABORT );
1433 inline const char *
strstr_s(
const char *haystack,
const char *needle)
1435 return const_cast<const char *
>(strstr(haystack, needle));
1438 inline char *
strstr_s(
char *haystack,
const char *needle)
1440 return const_cast<char *
>(strstr(haystack, needle));
1445 return const_cast<const char *
>(strchr(s, c));
1450 return const_cast<char *
>(strchr(s, c));
1455 long int ipow(
long,
long );
1474 char *
PrintEfmt(
const char *fmt,
double val );
1476 #define PrintEfmt( F, V ) F, V
1486 double sexp(
double x);
1492 double dsexp(
double x);
1498 double plankf(
long int ip);
1507 template<
typename Integrand, methods Method>
1511 double numPoints, weights[16], c[16];
1516 double weights_temp[16] = {
1517 .35093050047350483e-2, .81371973654528350e-2, .12696032654631030e-1, .17136931456510717e-1,
1518 .21417949011113340e-1, .25499029631188088e-1, .29342046739267774e-1, .32911111388180923e-1,
1519 .36172897054424253e-1, .39096947893535153e-1, .41655962113473378e-1, .43826046502201906e-1,
1520 .45586939347881942e-1, .46922199540402283e-1, .47819360039637430e-1, .48270044257363900e-1};
1522 double c_temp[16] = {
1523 .498631930924740780, .49280575577263417, .4823811277937532200, .46745303796886984000,
1524 .448160577883026060, .42468380686628499, .3972418979839712000, .36609105937014484000,
1525 .331522133465107600, .29385787862038116, .2534499544661147000, .21067563806531767000,
1526 .165934301141063820, .11964368112606854, .7223598079139825e-1, .24153832843869158e-1};
1528 for(
long i=0; i<numPoints; i++ )
1530 weights[i] = weights_temp[i];
1538 double a = 0.5*(max+
min),
1542 for(
long i=0; i< numPoints; i++ )
1543 total += b * weights[i] * ( func(a+b*c[i]) + func(a-b*c[i]) );
1555 double qg32(
double,
double,
double(*)(
double) );
1569 void spsort(
realnum x[],
long int n,
long int iperm[],
int kflag,
int *ier);
1580 # pragma warning( disable : 4127 )
1582 # pragma warning( disable : 4996 )
1584 # pragma warning( disable : 4056 )
1586 # pragma warning( disable : 4514 )
1589 # pragma warning( disable : 4512 )
1591 #ifdef __INTEL_COMPILER
1592 # pragma warning( disable : 1572 )
multi_arr< double, 3 > collrates
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
struct t_CollRatesArray CollRateCoeffArray
const char * routine() const
bool FindAndErase(string &str, const string &substr)
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)
void * MyCalloc(size_t num, size_t size)
double hmrate4(double a, double b, double c, double te)
int dbg_printf(int debug, const char *fmt,...)
double fudge(long int ipnt)
double ee1_safe(double x)
void * MyRealloc(void *p, size_t size)
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)
bool lgAssertAbort() const
void uncaps(char *chCard)
element_type * data() const
int GetQuote(char *chLabel, char *chCard, char *chCardRaw, bool lgABORT)
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)
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
auto_vec(element_type *p=NULL)
void enter(const char *name)
const int INPUT_LINE_LENGTH
double qg32(double, double, double(*)(double))
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 sum(double min, double max, Integrand func)
double AnuUnit(realnum energy)
void MyAssert(const char *file, int line, const char *comment)
const char * comment() const
long int ipow(long, long)
struct t_CollSplinesArray CollSplinesArray
double csphot(long int inu, long int ithr, long int iofset)
auto_vec(auto_vec_ref< element_type > r)
const int FILENAME_PATH_LENGTH
sys_float SDIV(sys_float x)
bool FindAndReplace(string &str, const string &substr, const string &newstr)
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)
struct t_StoutColls StoutColls
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)