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
219extern long int nzone;
351double fudge(
long int ipnt);
373void *
MyMalloc(
size_t size,
const char *file,
int line);
379void *
MyCalloc(
size_t num,
size_t size);
391void 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
464int dbg_printf(
int debug,
const char *fmt, ...);
467int 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
546 fprintf(
ioQQQ,
"DISASTER Assertion failure at %s:%ld\n%s\n",
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 )
610 if(
cpu.i().lgAssertAbort() )
613 throw out_of_range( str );
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) ) );
710inline char TorF(
bool l ) {
return l ?
'T' :
'F'; }
714inline bool is_odd(
int j ) {
return (j&1) == 1; }
715inline bool is_odd(
long j ) {
return (j&1L) == 1L; }
719inline long nint(
double x ) {
return static_cast<long>( (x < 0.) ? x-0.5 : x+0.5 ); }
723inline long min(
int a,
long b ) {
long c = a;
return ( (c < b) ? c : b ); }
724inline long min(
long a,
int b ) {
long c = b;
return ( (a < c) ? a : c ); }
725inline double min(
sys_float a,
double b ) {
double c = a;
return ( (c < b) ? c : b ); }
726inline double min(
double a,
sys_float b ) {
double c = b;
return ( (a < c) ? a : c ); }
731double powi(
double ,
long int );
735#ifndef HAVE_POW_DOUBLE_INT
736inline double pow(
double x,
int i ) {
return powi( x,
long(i) ); }
739#ifndef HAVE_POW_DOUBLE_LONG
740inline 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
752inline double pow(
sys_float x,
double y ) {
return pow(
double(x), y ); }
755#ifndef HAVE_POW_DOUBLE_FLOAT
756inline 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)))
775inline long max(
int a,
long b ) {
long c = a;
return ( (c > b) ? c : b ); }
776inline long max(
long a,
int b ) {
long c = b;
return ( (a > c) ? a : c ); }
777inline double max(
sys_float a,
double b ) {
double c = a;
return ( (c > b) ? c : b ); }
778inline 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);
808inline int sign3( T x ) {
return ( x < T() ) ? -1 : ( ( x > T() ) ? 1 : 0 ); }
816# pragma warning( disable : 4127 )
825 if( sx == 0 && sy == 0 )
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 )
889inline 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 )
931inline T
pow2(T a) {
return a*a; }
938inline T
pow3(T a) {
return a*a*a; }
945inline 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() );
1002inline 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)
1048inline 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)) );
1083template<
class T>
inline T*
get_ptr(valarray<T> &v)
1091template<
class T>
inline const T*
get_ptr(
const valarray<T> &v)
1093 return const_cast<const T*
>(&
const_cast<valarray<T>&
>(v)[0]);
1095template<
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() );
1324void 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)
1354double csphot(
long int inu,
long int ithr,
long int iofset);
1360double RandGauss(
double xMean,
double s );
1374void cap4(
char *chCAP ,
const char *chLab);
1378void uncaps(
char *chCard );
1382void caps(
char *chCard );
1391double ee1(
double x);
1414long nMatch(
const char *chKey,
1415 const char *chCard);
1426int GetQuote(
char *chLabel,
char *chCard,
char *chCardRaw,
bool lgABORT );
1429inline const char *
strstr_s(
const char *haystack,
const char *needle)
1431 return const_cast<const char *
>(strstr(haystack, needle));
1434inline 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));
1451long int ipow(
long,
long );
1470char *
PrintEfmt(
const char *fmt,
double val );
1472#define PrintEfmt( F, V ) F, V
1482double sexp(
double x);
1488double dsexp(
double x);
1494double plankf(
long int ip);
1503template<
typename Integrand, methods Method>
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};
1534 double a = 0.5*(
max+
min),
1539 total += b *
weights[i] * ( func(a+b*
c[i]) + func(a-b*
c[i]) );
1551double qg32(
double,
double,
double(*)(
double) );
1565void 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 )
double csphot(long int inu, long int ithr, long int iofset)
double plankf(long int ip)
const int FILENAME_PATH_LENGTH_2
const int FILENAME_PATH_LENGTH
sys_float sexp(sys_float x)
void * MyMalloc(size_t size, const char *file, int line)
double MyGaussRand(double PctUncertainty)
bool FindAndReplace(string &str, const string &substr, const string &newstr)
struct t_CollSplinesArray CollSplinesArray
long nMatch(const char *chKey, const char *chCard)
double ee1_safe(double x)
void * MyCalloc(size_t num, size_t size)
const int NHYDRO_MAX_LEVEL
void PrintE93(FILE *, double)
const double DEPTH_OFFSET
double qg32(double, double, double(*)(double))
struct t_CollRatesArray CollRateCoeffArray
NORETURN void BadRead(void)
void PrintE82(FILE *, double)
double fudge(long int ipnt)
const int INPUT_LINE_LENGTH
struct t_StoutColls StoutColls
sys_float safe_div(sys_float x, sys_float y, sys_float res_0by0)
int dbg_printf(int debug, const char *fmt,...)
int dprintf(FILE *fp, const char *format,...)
double RandGauss(double xMean, double s)
NORETURN void OUT_OF_RANGE(const char *str)
void cap4(char *chCAP, const char *chLab)
void MyAssert(const char *file, int line, const char *comment)
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
void PrintE71(FILE *, double)
double AnuUnit(realnum energy)
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
bool fp_bound_tol(sys_float lo, sys_float x, sys_float hi, sys_float tol)
void * MyRealloc(void *p, size_t size)
const char * strstr_s(const char *haystack, const char *needle)
int GetQuote(char *chLabel, char *chCard, char *chCardRaw, bool lgABORT)
double hmrate4(double a, double b, double c, double te)
long int ipow(long, long)
const char * strchr_s(const char *s, int c)
bool fp_bound(sys_float lo, sys_float x, sys_float hi, int n=3)
bool fp_equal(sys_float x, sys_float y, int n=3)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
void spsort(realnum x[], long int n, long int iperm[], int kflag, int *ier)
NORETURN void TotalInsanity(void)
sys_float SDIV(sys_float x)
bool FindAndErase(string &str, const string &substr)
void cdPrepareExit(exit_type)
void uncaps(char *chCard)
void invalidate_array(T *p, size_t size)
bool fp_equal_tol(sys_float x, sys_float y, sys_float tol)
double powi(double, long int)
istream & SafeGetline(istream &is, string &t)
double sum(double min, double max, Integrand func)
void reset(element_type *p=NULL)
element_type * data() const
auto_vec(element_type *p=NULL)
element_type * get() const
element_type & operator[](ptrdiff_t n) const
auto_vec(auto_vec_ref< element_type > r)
auto_vec & operator=(auto_vec &p)
const char * comment() const
const char * file() const
bad_assert(const char *file, long line, const char *comment)
const char * file() const
exit_type exit_status() const
const char * routine() const
cloudy_exit(const char *routine, const char *file, long line, exit_type exit_code)
const char * name() const
debugtrace(const char *funcname)
void leave(const char *name)
void enter(const char *name)
void leave(const char *) const
void enter(const char *) const
void set_NaN(sys_float &x)
multi_arr< double, 3 > collrates