Go to the documentation of this file.
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"
108 #define float PLEASE_USE_REALNUM_NOT_FLOAT
113 #define STATIC_ASSERT(x) ((void)StaticAssertFailed< (x) == true >())
138 #define EXIT_SUCCESS ES_SUCCESS
140 #define EXIT_FAILURE ES_FAILURE
219 extern long int nzone;
351 double fudge(
long int ipnt);
373 void *
MyMalloc(
size_t size,
const char *file,
int line);
379 void *
MyCalloc(
size_t num,
size_t size);
391 void MyAssert(
const char *file,
int line,
const char *comment);
419 const char*
file()
const throw()
434 #define cdEXIT( FAIL ) throw cloudy_exit( __func__, __FILE__, __LINE__, FAIL )
437 #define puts( STR ) Using_puts_before_cdEXIT_is_no_longer_needed
464 int dbg_printf(
int debug,
const char *fmt, ...);
467 int dprintf(FILE *fp,
const char *format, ...);
498 # define MALLOC(exp) (malloc(exp))
501 # define MALLOC(exp) (MyMalloc(exp,__FILE__, __LINE__))
507 # define CALLOC calloc
510 # define CALLOC MyCalloc
516 # define REALLOC realloc
519 # define REALLOC MyRealloc
543 bad_assert(
const char* file,
long line,
const char* comment);
546 fprintf(
ioQQQ,
"DISASTER Assertion failure at %s:%ld\n%s\n",
547 p_file, p_line, p_comment);
553 const char*
file()
const throw()
576 # define ASSERT(exp) ((void)0)
578 # define ASSERT(exp) \
580 if (UNLIKELY(!(exp))) \
582 bad_assert aa(__FILE__,__LINE__,"Failed: " #exp); \
583 if( cpu.i().lgAssertAbort() ) \
596 # define ASSERT(exp) ((void)0)
598 # define ASSERT(exp) \
601 MyAssert(__FILE__, __LINE__, "Failed: " #exp); \
606 #define MESSAGE_ASSERT(msg, exp) ASSERT( (msg) ? (exp) : false )
613 throw out_of_range( str );
620 #define isnan MyIsnan
638 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'>',name);
642 fprintf(p_fp,
"%*c%s\n",p_callLevel,
'<',name);
659 template<
class Trace>
667 Trace::Inst().enter(p_name);
671 Trace::Inst().leave(p_name);
681 #define DEBUG_ENTRY( funcname ) debugtrace<t_debug> DEBUG_ENTRY( funcname )
684 #define DEBUG_ENTRY( funcname ) ((void)0)
686 #define DEBUG_ENTRY( funcname ) debugtrace<t_nodebug> DEBUG_ENTRY( funcname )
693 return static_cast<char>(
tolower(
static_cast<int>(c) ) );
697 return static_cast<unsigned char>(
tolower(
static_cast<int>(c) ) );
702 return static_cast<char>(
toupper(
static_cast<int>(c) ) );
706 return static_cast<unsigned char>(
toupper(
static_cast<int>(c) ) );
710 inline char TorF(
bool l ) {
return l ?
'T' :
'F'; }
714 inline bool is_odd(
int j ) {
return (j&1) == 1; }
715 inline bool is_odd(
long j ) {
return (j&1L) == 1L; }
719 inline long nint(
double x ) {
return static_cast<long>( (x < 0.) ? x-0.5 : x+0.5 ); }
723 inline long min(
int a,
long b ) {
long c = a;
return ( (c < b) ? c : b ); }
724 inline long min(
long a,
int b ) {
long c = b;
return ( (a < c) ? a : c ); }
725 inline double min(
sys_float a,
double b ) {
double c = a;
return ( (c < b) ? c : b ); }
726 inline double min(
double a,
sys_float b ) {
double c = b;
return ( (a < c) ? a : c ); }
731 double powi(
double ,
long int );
735 #ifndef HAVE_POW_DOUBLE_INT
736 inline double pow(
double x,
int i ) {
return powi( x,
long(i) ); }
739 #ifndef HAVE_POW_DOUBLE_LONG
740 inline double pow(
double x,
long i ) {
return powi( x, i ); }
743 #ifndef HAVE_POW_FLOAT_INT
747 #ifndef HAVE_POW_FLOAT_LONG
751 #ifndef HAVE_POW_FLOAT_DOUBLE
752 inline double pow(
sys_float x,
double y ) {
return pow(
double(x), y ); }
755 #ifndef HAVE_POW_DOUBLE_FLOAT
756 inline double pow(
double x,
sys_float y ) {
return pow( x,
double(y) ); }
766 #define MIN3(a,b,c) (min(min(a,b),c))
771 #define MIN4(a,b,c,d) (min(min(a,b),min(c,d)))
775 inline long max(
int a,
long b ) {
long c = a;
return ( (c > b) ? c : b ); }
776 inline long max(
long a,
int b ) {
long c = b;
return ( (a > c) ? a : c ); }
777 inline double max(
sys_float a,
double b ) {
double c = a;
return ( (c > b) ? c : b ); }
778 inline double max(
double a,
sys_float b ) {
double c = b;
return ( (a > c) ? a : c ); }
787 #define MAX3(a,b,c) (max(max(a,b),c))
792 #define MAX4(a,b,c,d) (max(max(a,b),max(c,d)))
802 return ( y < T() ) ? -abs(x) : abs(x);
808 inline int sign3( T x ) {
return ( x < T() ) ? -1 : ( ( x > T() ) ? 1 : 0 ); }
816 # pragma warning( disable : 4127 )
825 if( sx == 0 && sy == 0 )
835 inline bool fp_equal(
double x,
double y,
int n=3 )
844 if( sx == 0 && sy == 0 )
851 return ( 1. -
min(x,y)/
max(x,y) < ((
double)n+0.1)*DBL_EPSILON );
861 ASSERT( tol >= FLT_EPSILON*
max(abs(x),abs(y)) );
862 return ( abs( x-y ) <= tol );
872 ASSERT( tol >= DBL_EPSILON*
max(abs(x),abs(y)) );
873 return ( abs( x-y ) <= tol );
885 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
sys_float)n+0.1f)*FLT_EPSILON )
889 inline bool fp_bound(
double lo,
double x,
double hi,
int n=3 )
897 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -((
double)n+0.1)*DBL_EPSILON )
909 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
921 if( ((hi-x)/(hi-lo))*((x-lo)/(hi-lo)) < -tol )
931 inline T
pow2(T a) {
return a*a; }
938 inline T
pow3(T a) {
return a*a*a; }
945 inline T
pow4(T a) { T b = a*a;
return b*b; }
969 if( sx == 0 && sy == 0 )
971 if(
isnan(res_0by0) )
979 return ( sx < 0 ) ? -FLT_MAX : FLT_MAX;
987 if( abs(x) < ay*FLT_MAX )
990 return ( sx*sy < 0 ) ? -FLT_MAX : FLT_MAX;
996 return safe_div( x, y, numeric_limits<sys_float>::quiet_NaN() );
1002 inline double safe_div(
double x,
double y,
double res_0by0)
1010 if( sx == 0 && sy == 0 )
1012 if(
isnan(res_0by0) )
1020 return ( sx < 0 ) ? -DBL_MAX : DBL_MAX;
1028 if( abs(x) < ay*DBL_MAX )
1031 return ( sx*sy < 0 ) ? -DBL_MAX : DBL_MAX;
1037 return safe_div( x, y, numeric_limits<double>::quiet_NaN() );
1046 #define HMRATE(a,b,c) hmrate4(a,b,c,phycon.te)
1048 inline double hmrate4(
double a,
double b,
double c,
double te )
1050 if( b == 0. && c == 0. )
1053 return a*pow(te/300.,b);
1055 return ( c/te <= 50. ) ? a*exp(-c/te) : 0.;
1057 return ( c/te <= 50. ) ? a*pow(te/300.,b)*exp(-c/te) : 0.;
1064 memset( p, -1, size );
1069 set_NaN( p, (
long)(size/
sizeof(
double)) );
1083 template<
class T>
inline T*
get_ptr(valarray<T> &v)
1091 template<
class T>
inline const T*
get_ptr(
const valarray<T> &v)
1093 return const_cast<const T*
>(&
const_cast<valarray<T>&
>(v)[0]);
1095 template<
class T>
inline const T*
get_ptr(
const vector<T> &v)
1097 return const_cast<const T*
>(&
const_cast<vector<T>&
>(v)[0]);
1156 reset( p.release() );
1324 void Split(
const string& str,
1326 vector<string>& lst,
1332 const string& substr,
1333 const string& newstr)
1335 string::size_type ptr = str.find( substr );
1336 if( ptr != string::npos )
1337 str.replace( ptr, substr.length(), newstr );
1338 return ptr != string::npos;
1344 const string& substr)
1354 double csphot(
long int inu,
long int ithr,
long int iofset);
1360 double RandGauss(
double xMean,
double s );
1374 void cap4(
char *chCAP ,
const char *chLab);
1378 void uncaps(
char *chCard );
1382 void caps(
char *chCard );
1391 double ee1(
double x);
1404 double FFmtRead(
const char *chCard,
1414 long nMatch(
const char *chKey,
1415 const char *chCard);
1426 int GetQuote(
char *chLabel,
char *chCard,
char *chCardRaw,
bool lgABORT );
1429 inline const char *
strstr_s(
const char *haystack,
const char *needle)
1431 return const_cast<const char *
>(strstr(haystack, needle));
1434 inline char *
strstr_s(
char *haystack,
const char *needle)
1436 return const_cast<char *
>(strstr(haystack, needle));
1441 return const_cast<const char *
>(strchr(s, c));
1446 return const_cast<char *
>(strchr(s, c));
1451 long int ipow(
long,
long );
1470 char *
PrintEfmt(
const char *fmt,
double val );
1472 #define PrintEfmt( F, V ) F, V
1482 double sexp(
double x);
1488 double dsexp(
double x);
1494 double plankf(
long int ip);
1503 template<
typename Integrand, methods Method>
1507 double numPoints, weights[16], c[16];
1512 double weights_temp[16] = {
1513 .35093050047350483e-2, .81371973654528350e-2, .12696032654631030e-1, .17136931456510717e-1,
1514 .21417949011113340e-1, .25499029631188088e-1, .29342046739267774e-1, .32911111388180923e-1,
1515 .36172897054424253e-1, .39096947893535153e-1, .41655962113473378e-1, .43826046502201906e-1,
1516 .45586939347881942e-1, .46922199540402283e-1, .47819360039637430e-1, .48270044257363900e-1};
1518 double c_temp[16] = {
1519 .498631930924740780, .49280575577263417, .4823811277937532200, .46745303796886984000,
1520 .448160577883026060, .42468380686628499, .3972418979839712000, .36609105937014484000,
1521 .331522133465107600, .29385787862038116, .2534499544661147000, .21067563806531767000,
1522 .165934301141063820, .11964368112606854, .7223598079139825e-1, .24153832843869158e-1};
1524 for(
long i=0; i<numPoints; i++ )
1526 weights[i] = weights_temp[i];
1534 double a = 0.5*(
max+
min),
1538 for(
long i=0; i< numPoints; i++ )
1539 total += b * weights[i] * ( func(a+b*c[i]) + func(a-b*c[i]) );
1551 double qg32(
double,
double,
double(*)(
double) );
1565 void spsort(
realnum x[],
long int n,
long int iperm[],
int kflag,
int *ier);
1576 # pragma warning( disable : 4127 )
1578 # pragma warning( disable : 4996 )
1580 # pragma warning( disable : 4056 )
1582 # pragma warning( disable : 4514 )
1585 # pragma warning( disable : 4512 )
1587 #ifdef __INTEL_COMPILER
1588 # pragma warning( disable : 1572 )
void PrintE71(FILE *, double)
auto_vec(element_type *p=NULL)
const int NHYDRO_MAX_LEVEL
NORETURN void BadRead(void)
long int ipow(long, long)
void PrintE93(FILE *, double)
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
struct t_CollSplinesArray CollSplinesArray
void * MyCalloc(size_t num, size_t size)
double ee1_safe(double x)
void * MyRealloc(void *p, size_t size)
void enter(const char *) const
double RandGauss(double xMean, double s)
void spsort(realnum x[], long int n, long int iperm[], int kflag, int *ier)
double AnuUnit(realnum energy)
const char * name() const
sys_float SDIV(sys_float x)
const char * strstr_s(const char *haystack, const char *needle)
double csphot(long int inu, long int ithr, long int iofset)
void PrintE82(FILE *, double)
void reset(element_type *p=NULL)
istream & SafeGetline(istream &is, string &t)
void leave(const char *) const
int dbg_printf(int debug, const char *fmt,...)
sys_float sexp(sys_float x)
const int FILENAME_PATH_LENGTH
bool lgAssertAbort() const
multi_arr< double, 3 > collrates
cloudy_exit(const char *routine, const char *file, long line, exit_type exit_code)
bool FindAndReplace(string &str, const string &substr, const string &newstr)
debugtrace(const char *funcname)
void cap4(char *chCAP, const char *chLab)
sys_float safe_div(sys_float x, sys_float y, sys_float res_0by0)
double sum(double min, double max, Integrand func)
NORETURN void TotalInsanity(void)
NORETURN void OUT_OF_RANGE(const char *str)
double plankf(long int ip)
void cdPrepareExit(exit_type)
void uncaps(char *chCard)
long nMatch(const char *chKey, const char *chCard)
int GetQuote(char *chLabel, char *chCard, char *chCardRaw, bool lgABORT)
void set_NaN(sys_float &x)
struct t_StoutColls StoutColls
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
bool FindAndErase(string &str, const string &substr)
const double DEPTH_OFFSET
auto_vec(auto_vec_ref< element_type > r)
void enter(const char *name)
bool fp_equal_tol(sys_float x, sys_float y, sys_float tol)
struct t_CollRatesArray CollRateCoeffArray
void * MyMalloc(size_t size, const char *file, int line)
const char * routine() const
double fudge(long int ipnt)
double hmrate4(double a, double b, double c, double te)
const char * comment() const
const int FILENAME_PATH_LENGTH_2
void MyAssert(const char *file, int line, const char *comment)
const int INPUT_LINE_LENGTH
void leave(const char *name)
double powi(double, long int)
bool fp_equal(sys_float x, sys_float y, int n=3)
double MyGaussRand(double PctUncertainty)
const char * file() const
bool fp_bound_tol(sys_float lo, sys_float x, sys_float hi, sys_float tol)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
const char * file() const
bool fp_bound(sys_float lo, sys_float x, sys_float hi, int n=3)
int dprintf(FILE *fp, const char *format,...)
element_type * data() const
void invalidate_array(T *p, size_t size)
double qg32(double, double, double(*)(double))
exit_type exit_status() const
element_type * get() const
const char * strchr_s(const char *s, int c)