9 extern "C" unsigned long fegettrapenable();
10 extern "C" void fesettrapenable(
unsigned long);
13 #if defined(__ia64) && defined(__INTEL_COMPILER) 14 extern "C" unsigned long fpgetmask();
15 extern "C" void fpsetmask(
unsigned long);
18 #if defined(__sun) || defined(__sgi) 20 #if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO) 25 #if defined(__alpha) && defined(__linux__) && defined(__GNUC__) 30 #if defined(__unix) || defined(__APPLE__) 34 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 35 #include <sys/types.h> 36 #include <sys/sysctl.h> 73 set_signal_handlers();
75 p_exit_status.resize(
ES_TOP,
"--undefined--" );
77 p_exit_status[
ES_FAILURE] =
"early termination";
79 p_exit_status[
ES_BOTCHES] =
"botched monitors";
105 Float_SNaN_Value = 0xffffffff;
107 if( big_endian() || little_endian() )
110 Float_SNaN_Value = 0xffbfffff;
115 Float_SNaN_Value = -1;
122 Float_SNaN_Value = -1;
127 if(
sizeof(
double) == 8 )
131 Double_SNaN_Value = 0xffffffffffffffff;
134 Double_SNaN_Value = 0xfff7ffffffbfffff;
140 Double_SNaN_Value = -1;
145 if(
sizeof(
double) == 8 )
149 Double_SNaN_Value[0] = 0xffffffff;
150 Double_SNaN_Value[1] = 0xffffffff;
155 Double_SNaN_Value[0] = 0xfff7ffff;
156 Double_SNaN_Value[1] = 0xffbfffff;
158 else if( little_endian() )
161 Double_SNaN_Value[0] = 0xffbfffff;
162 Double_SNaN_Value[1] = 0xfff7ffff;
167 Double_SNaN_Value[0] = -1;
168 Double_SNaN_Value[1] = -1;
175 Double_SNaN_Value[0] = -1;
176 Double_SNaN_Value[1] = -1;
189 test_float = FLT_MIN;
190 test_double = DBL_MIN;
193 p_lgAssertAbort =
false;
198 # if defined(_SC_NPROCESSORS_ONLN) 199 n_avail_CPU = sysconf(_SC_NPROCESSORS_ONLN);
200 # elif defined(_SC_NPROC_ONLN) 201 n_avail_CPU = sysconf(_SC_NPROC_ONLN);
202 # elif defined(_SC_CRAY_NCPU) 203 n_avail_CPU = sysconf(_SC_CRAY_NCPU);
204 # elif defined(_WIN32) 205 str = getenv(
"NUMBER_OF_PROCESSORS" );
208 int found = sscanf( str,
"%ld", &n_avail_CPU );
216 # elif defined(HW_AVAILCPU) 218 size_t len =
sizeof(n_avail_CPU);
220 mib[1] = HW_AVAILCPU;
221 sysctl(mib, 2, &n_avail_CPU, &len, NULL, 0);
222 if( n_avail_CPU < 1 )
225 sysctl(mib, 2, &n_avail_CPU, &len, NULL, 0);
226 if( n_avail_CPU < 1 )
240 p_lgMPISingleRankMode =
false;
244 str = getenv(
"COMPUTERNAME" );
246 str = getenv(
"HOSTNAME" );
250 strncpy( HostName, str,
STDLEN );
252 strncpy( HostName,
"unknown",
STDLEN );
253 HostName[
STDLEN-1] =
'\0';
256 const char *path = getenv(
"CLOUDY_DATA_PATH" );
259 string chSearchPathRaw = ( path != NULL ) ?
string( path ) : string( CLOUDY_DATA_PATH );
262 string separator(
";" );
263 p_chDirSeparator =
'\\';
265 string separator(
":" );
266 p_chDirSeparator =
'/';
269 chSearchPath.push_back(
"" );
271 chSearchPath.push_back(
"" );
273 for( vector<string>::size_type
i=0;
i < chSearchPath.size(); ++
i )
275 if( chSearchPath[
i].length() > 0 )
278 char chEnd = *chSearchPath[
i].rbegin();
281 if( chEnd != p_chDirSeparator )
282 chSearchPath[
i] += p_chDirSeparator;
298 # if defined(_MSC_VER) 299 volatile unsigned int NewMask;
304 NewMask = _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_INVALID;
307 _controlfp( NewMask , _MCW_EM );
313 # elif defined(__GNUC__) && ( defined(__i386) || defined(__amd64) ) && !defined(__clang__) 314 volatile unsigned int Old_Mask, New_Mask;
315 # if defined(__SSE__) || defined(__SSE2__) 316 volatile unsigned int SSE_Mask;
319 # define _FPU_MASK_IM 0x01 320 # define _FPU_MASK_DM 0x02 321 # define _FPU_MASK_ZM 0x04 322 # define _FPU_MASK_OM 0x08 323 # define _FPU_MASK_UM 0x10 324 # define _FPU_MASK_PM 0x20 334 volatile unsigned int UnMask = ~((
unsigned int)( _FPU_MASK_ZM | _FPU_MASK_IM | _FPU_MASK_OM ));
336 __asm__
volatile(
"fnstcw %0" :
"=m" (*&Old_Mask));
338 New_Mask = Old_Mask & UnMask;
340 __asm__
volatile(
"fldcw %0" : :
"m" (*&New_Mask));
342 # if defined(__SSE__) || defined(__SSE2__) 344 # if defined(FLUSH_DENORM_TO_ZERO) 355 __asm__
volatile(
"ldmxcsr %0" : :
"m" (*&SSE_Mask) );
360 # elif defined(__ia64) 362 # define FPSR_TRAP_VD (1 << 0) 363 # define FPSR_TRAP_DD (1 << 1) 364 # define FPSR_TRAP_ZD (1 << 2) 365 # define FPSR_TRAP_OD (1 << 3) 366 # define FPSR_TRAP_UD (1 << 4) 367 # define FPSR_TRAP_ID (1 << 5) 369 # define FPSR_SF0_FTZ (1 << 6) 371 # if defined(__GNUC_EXCL__) 373 # define _IA64_REG_AR_FPSR 40 375 # define ia64_getreg( regnum ) __asm__ volatile( "mov %0=ar%1" : "=r" (fpsr) : "i"(regnum) ) 376 # define ia64_setreg( regnum, val ) __asm__ volatile( "mov ar%0=%1" :: "i" (regnum), "r"(val): "memory" ) 377 # define ia64_serialize __asm__ volatile( "srlz.i" ); 379 volatile unsigned long fpsr, flags = FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
381 ia64_getreg( _IA64_REG_AR_FPSR );
383 # if defined(FLUSH_DENORM_TO_ZERO) 384 fpsr |= FPSR_SF0_FTZ;
386 ia64_setreg( _IA64_REG_AR_FPSR, fpsr );
390 # elif defined(__INTEL_COMPILER) 392 unsigned long fpsr = fpgetmask();
393 fpsr |= FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
395 # elif defined(__HP_aCC) 397 unsigned long fpsr = fegettrapenable();
398 fpsr |= FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
399 fesettrapenable( fpsr );
403 # elif defined(__sun) || defined(__sgi) 408 # if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO) 445 nonstandard_arithmetic();
450 mask = mask | FP_X_INV | FP_X_OFL | FP_X_DZ;
453 # elif defined(__alpha) && defined(__linux__) && defined(__GNUC__) 458 # ifdef FE_NONIEEE_ENV 462 fesetenv(FE_NONIEEE_ENV);
475 p_action.sa_handler = &signal_handler;
476 sigemptyset( &p_action.sa_mask );
477 p_action.sa_flags = SA_NODEFER;
479 p_default.sa_handler = SIG_DFL;
480 sigemptyset( &p_default.sa_mask );
481 p_default.sa_flags = SA_NODEFER;
483 for(
int sig=1; sig <= 31; sig++ )
486 if( sigaction( sig, NULL, NULL ) == 0 )
488 if( sig != SIGSTOP && sig != SIGCONT )
489 sigaction( sig, action(), NULL );
494 signal( SIGABRT, &signal_handler );
495 signal( SIGFPE, &signal_handler );
496 signal( SIGILL, &signal_handler );
497 signal( SIGINT, &signal_handler );
498 signal( SIGSEGV, &signal_handler );
499 signal( SIGTERM, &signal_handler );
510 signal( sig, &signal_handler );
518 fprintf(
ioQQQ,
"The path is:\n");
519 for( vector<string>::size_type
i=1;
i < chSearchPath.size()-1; ++
i )
520 fprintf(
ioQQQ,
" ==%s==\n", chSearchPath[
i].c_str() );
528 vector<string>::size_type begin, end;
559 string FileName( fname );
560 for( vector<string>::size_type
i=begin;
i < end; ++
i )
570 fprintf(
ioQQQ,
"\nI could not open the data file %s\n\n", fname );
572 fprintf(
ioQQQ,
"\nPROBLEM DISASTER I could not open the data file %s\n\n", fname );
577 fprintf(
ioQQQ,
"Although there may be other reasons you have received this error,\n");
578 fprintf(
ioQQQ,
"the most likely are that the path has not been properly set\n");
579 fprintf(
ioQQQ,
"or that the path points to an old version of the data.\n\n");
580 fprintf(
ioQQQ,
"Please have a look at the file path.h in the source directory\n");
581 fprintf(
ioQQQ,
"to check how the variable CLOUDY_DATA_PATH is set - \n");
582 fprintf(
ioQQQ,
"it should give the location of the data files I need.\n");
583 fprintf(
ioQQQ,
"These are the files in the data download from the web site.\n\n");
584 fprintf(
ioQQQ,
"Recompile the code with the correct data path set in path.h\n");
585 fprintf(
ioQQQ,
"or use the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n to set the\n");
586 fprintf(
ioQQQ,
"path from a bash command prompt.\n\n");
594 fprintf(
ioQQQ,
"These are all the paths I tried:\n" );
595 for( vector<string>::const_iterator ptr=PathList.begin(); ptr != PathList.end(); ++ptr )
596 fprintf(
ioQQQ,
" ==%s==\n", ptr->c_str() );
600 fprintf(
ioQQQ,
"\nAlthough there may be other reasons you have received this error,\n");
601 fprintf(
ioQQQ,
"the most likely are that you mistyped the file name, or that you\n");
602 fprintf(
ioQQQ,
"are running Cloudy in the wrong directory. If you are running a\n");
603 fprintf(
ioQQQ,
"COMPILE command, this needs to be done in the data directory.\n\n");
604 fprintf(
ioQQQ,
"Otherwise, please have a look at the file path.h in the source\n");
605 fprintf(
ioQQQ,
"directory to check how the variable CLOUDY_DATA_PATH is set - \n");
606 fprintf(
ioQQQ,
"it should give the location of the data files I need.\n");
607 fprintf(
ioQQQ,
"These are the files in the data download from the web site.\n\n");
608 fprintf(
ioQQQ,
"Recompile the code with the correct data path set in path.h\n");
609 fprintf(
ioQQQ,
"or use the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n to set the\n");
610 fprintf(
ioQQQ,
"path from a bash command prompt.\n\n");
613 fprintf(
ioQQQ,
"Sorry.\n\n\n");
624 vector<string> PathList;
628 vector<string>::const_iterator ptr;
629 for( ptr=PathList.begin(); ptr != PathList.end() && handle == NULL; ++ptr )
631 handle = fopen( ptr->c_str(), mode );
633 fprintf(
ioQQQ,
" open_data trying %s mode %s handle %p\n", ptr->c_str(), mode, handle );
636 if( handle == NULL && lgAbort )
651 vector<string> PathList;
654 ASSERT( !stream.is_open() );
655 vector<string>::const_iterator ptr;
656 for( ptr=PathList.begin(); ptr != PathList.end() && !stream.is_open(); ++ptr )
658 stream.open( ptr->c_str(), mode );
660 fprintf(
ioQQQ,
" open_data trying %s succes? %c\n", ptr->c_str(),
TorF(stream.is_open()) );
663 if( !stream.is_open() &&
lgAbort )
689 int32 *y =
reinterpret_cast<int32*
>(x);
690 for( i=0; i < n; i++ )
695 for( i=0; i < n; i++ )
702 if(
sizeof(
double) == 8 )
707 int32 *y =
reinterpret_cast<int32*
>(&x);
722 if(
sizeof(
double) == 8 )
725 int64 *y =
reinterpret_cast<int64*
>(x);
726 for( i=0; i < n; i++ )
729 int32 *y =
reinterpret_cast<int32*
>(x);
730 for( i=0; i < n; i++ )
739 for( i=0; i < n; i++ )
747 if(
sizeof(
sys_float) == 4 && FLT_MAX_EXP-FLT_MIN_EXP+3 == 256 )
749 const int32 *p =
reinterpret_cast<const int32*
>(&x);
750 int32 r = *p & 0x7f800000; r ^= 0x7f800000;
751 int32 s = *p & 0x007fffff;
752 return ( r == 0 && s != 0 );
762 if(
sizeof(
double) == 8 && DBL_MAX_EXP-DBL_MIN_EXP+3 == 2048 )
765 const int64 *p =
reinterpret_cast<const int64*
>(&x);
766 int64 r = *p & 0x7ff0000000000000; r ^= 0x7ff0000000000000;
767 int64 s = *p & 0x000fffffffffffff;
768 return ( r == 0 && s != 0 );
770 const int32 *p =
reinterpret_cast<const int32*
>(&x);
773 int32 r = p[1] & 0x7ff00000; r ^= 0x7ff00000;
774 int32 s = p[1] & 0x000fffff; s |= p[0];
775 return ( r == 0 && s != 0 );
779 int32 r = p[0] & 0x7ff00000; r ^= 0x7ff00000;
780 int32 s = p[0] & 0x000fffff; s |= p[1];
781 return ( r == 0 && s != 0 );
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
static void signal_handler(int sig)
NORETURN void TotalInsanity(void)
void set_NaN(sys_float &x)
void enable_traps() const
int32 Double_SNaN_Value[2]
bool MyIsnan(const sys_float &x)
STATIC NORETURN void AbortErrorMessage(const char *fname, vector< string > &PathList, access_scheme scheme)
void printDataPath() const
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
bool little_endian() const
void getPathList(const char *fname, vector< string > &PathList, access_scheme scheme) const
#define DEBUG_ENTRY(funcname)
void set_signal_handlers()
vector< string > chSearchPath