cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cddefines.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef _CDDEFINES_H_
5 #define _CDDEFINES_H_
6 
7 #ifdef _MSC_VER
8 /* disable warning that conditional expression is constant, true or false in if */
9 # pragma warning( disable : 4127 )
10 /* we are not using MS foundation class */
11 # ifndef WIN32_LEAN_AND_MEAN
12 # define WIN32_LEAN_AND_MEAN
13 # endif
14 #endif
15 /* these headers are needed by all files */
16 /*lint -e129 these resolve several issues pclint has with my system headers */
17 /*lint -e78 */
18 /*lint -e830 */
19 /*lint -e38 */
20 /*lint -e148 */
21 /*lint -e114 */
22 /*lint -e18 */
23 /*lint -e49 */
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include <assert.h>
28 #include <string.h>
29 #include <float.h>
30 #include <limits.h>
31 #include <time.h>
32 #include <signal.h>
33 #include <string>
34 #include <sstream>
35 #include <vector>
36 #include <valarray>
37 #include <complex>
38 #include <map>
39 #include <memory>
40 #include <stdexcept>
41 #ifdef DMALLOC
42 #include <dmalloc.h>
43 #endif
44 /*lint +e18 */
45 /*lint +e49 */
46 /*lint +e38 */
47 /*lint +e148 */
48 /*lint +e830 */
49 /*lint +e78 */
50 /*lint -e129 */
51 
52 using namespace std;
53 
55 #ifndef EXTERN
56 #define EXTERN extern
57 #endif
58 
59 #undef STATIC
60 #ifdef USE_GPROF
61 #define STATIC
62 #else
63 #define STATIC static
64 #endif
65 
66 #ifdef FLT_IS_DBL
67 typedef double realnum;
68 #else
69 typedef float realnum;
70 #endif
71 
72 typedef float sys_float;
73 // prevent explicit float's from creeping back into the code
74 #define float PLEASE_USE_REALNUM_NOT_FLOAT
75 
76 /* make sure this is globally visible as well! */
77 #include "cpu.h"
78 
79 //*************************************************************************
80 //
98 //
99 // This implementation has been obtained from Wikipedia
100 //
101 //*************************************************************************
102 
103 template<typename T> class Singleton
104 {
105 public:
106  static T& Inst()
107  {
108  static T instance; // assumes T has a protected default constructor
109  return instance;
110  }
111 };
112 
113 /**************************************************************************
114  *
115  * these are variables and pointers for output from the code, used everywhere
116  * declared extern here, and definition is in cddefines.cpp
117  *
118  **************************************************************************/
119 
123 EXTERN FILE *ioQQQ;
124 
126 
127 extern FILE *ioMAP;
128 
132 
135 
139 
143 
147 
150 EXTERN long int nzone;
151 
153 EXTERN double fnzone;
154 
157 EXTERN long int iteration;
158 
161 
168 extern const double ZeroNum;
169 
170 /**************************************************************************
171  *
172  * these are constants used to dimension several vectors and index arrays
173  *
174  **************************************************************************/
175 
180 const int FILENAME_PATH_LENGTH = 200;
181 
184 
188 const int INPUT_LINE_LENGTH = 200;
189 
192 const int LIMELM = 30;
193 
195 const int NISO = 2;
196 
200 const int NHYDRO_MAX_LEVEL = 401;
201 
203 const int N_H_MOLEC = 8;
204 
205 #if 0
206 
207 const double TEMP_STOP_DEFAULT = 4000.;
209 const double TEMP_LIMIT_HIGH = 1e10;
211 const double TEMP_LIMIT_LOW = 2.8;
212 #endif
213 
215 const double DEPTH_OFFSET = 1.e-30;
216 
217  /* these are flags for various colliders that are used across the code */
218 enum collider {
223  //ipATOMH,
224  //ipHE_2PLUS,
225  //ipH2_ORTHO,
226  //ipH2_PARA,
228 };
229 
230 /* indices within recombination coefficient array */
231 /* ipRecEsc is state specific escape probability*/
232 const int ipRecEsc = 2;
233 /* the net escaping, including destruction by background and optical deepth*/
234 const int ipRecNetEsc = 1;
235 /* ipRecRad is state specific radiative recombination rate*/
236 const int ipRecRad = 0;
241 /* these specify the form of the line redistribution function */
242 /* partial redistribution with wings */
243 const int ipPRD = 1;
244 /* complete redistribution, core only, no wings, Hummer's K2 function */
245 const int ipCRD = -1;
246 /* complete redistribution with wings */
247 const int ipCRDW = 2;
248 /* redistribution function for Lya, calls Hummer routine for H-like series only */
249 const int ipLY_A = -2;
250 /* core function for K2 destruction */
251 const int ipDEST_K2 = 1;
252 /* core function for complete redist destruction */
253 const int ipDEST_INCOM = 2;
254 /* core function for simple destruction */
255 const int ipDEST_SIMPL = 3;
256 
259 const int ipH1s = 0;
260 const int ipH2s = 1;
261 const int ipH2p = 2;
262 const int ipH3s = 3;
263 const int ipH3p = 4;
264 const int ipH3d = 5;
265 const int ipH4s = 6;
266 const int ipH4p = 7;
267 const int ipH4d = 8;
268 const int ipH4f = 9;
269 const int ipH5s = 10;
270 const int ipH5p = 11;
271 const int ipH5d = 12;
272 const int ipH5f = 13;
273 const int ipH5g = 14;
274 const int ipH6s = 15;
275 
278 /* level 1 */
279 const int ipHe1s1S = 0;
280 
281 /* level 2 */
282 const int ipHe2s3S = 1;
283 const int ipHe2s1S = 2;
284 const int ipHe2p3P0 = 3;
285 const int ipHe2p3P1 = 4;
286 const int ipHe2p3P2 = 5;
287 const int ipHe2p1P = 6;
288 
289 /* level 3 */
290 const int ipHe3s3S = 7;
291 const int ipHe3s1S = 8;
292 const int ipHe3p3P = 9;
293 const int ipHe3d3D = 10;
294 const int ipHe3d1D = 11;
295 const int ipHe3p1P = 12;
296 
297 /* level 4 */
298 const int ipHe4s3S = 13;
299 const int ipHe4s1S = 14;
300 const int ipHe4p3P = 15;
301 const int ipHe4d3D = 16;
302 const int ipHe4d1D = 17;
303 const int ipHe4f3F = 18;
304 const int ipHe4f1F = 19;
305 const int ipHe4p1P = 20;
306 
310 const int ipH_LIKE = 0;
311 const int ipHE_LIKE = 1;
312 const int ipLI_LIKE = 2;
313 const int ipBE_LIKE = 3;
314 const int ipB_LIKE = 4;
315 const int ipC_LIKE = 5;
316 const int ipN_LIKE = 6;
317 const int ipO_LIKE = 7;
318 const int ipF_LIKE = 8;
319 
321 const int ipHYDROGEN = 0;
322 const int ipHELIUM = 1;
323 const int ipLITHIUM = 2;
324 const int ipBERYLLIUM = 3;
325 const int ipBORON = 4;
326 const int ipCARBON = 5;
327 const int ipNITROGEN = 6;
328 const int ipOXYGEN = 7;
329 const int ipFLUORINE = 8;
330 const int ipNEON = 9;
331 const int ipSODIUM = 10;
332 const int ipMAGNESIUM = 11;
333 const int ipALUMINIUM = 12;
334 const int ipSILICON = 13;
335 const int ipPHOSPHORUS = 14;
336 const int ipSULPHUR = 15;
337 const int ipCHLORINE = 16;
338 const int ipARGON = 17;
339 const int ipPOTASSIUM = 18;
340 const int ipCALCIUM = 19;
341 const int ipSCANDIUM = 20;
342 const int ipTITANIUM = 21;
343 const int ipVANADIUM = 22;
344 const int ipCHROMIUM = 23;
345 const int ipMANGANESE = 24;
346 const int ipIRON = 25;
347 const int ipCOBALT = 26;
348 const int ipNICKEL = 27;
349 const int ipCOPPER = 28;
350 const int ipZINC = 29;
351 
352 /***************************************************************************
353  * the following are prototypes for some routines that are part of the
354  * debugging process - they come and go in any particular sub.
355  * it is not necessary to declare them when used since they are defined here
356  **************************************************************************/
357 
366 double fudge(long int ipnt);
367 
371 void broken(void);
372 
375 void fixit(void);
376 
378 void CodeReview(void);
379 
381 void TestCode(void);
382 
388 void *MyMalloc(size_t size, const char *file, int line);
389 
394 void *MyCalloc(size_t num, size_t size);
395 
400 void *MyRealloc(void *p, size_t size);
401 
406 void MyAssert(const char *file, int line);
407 
411 NORETURN void cdExit(int iexit);
412 
414 {
415  const char* p_routine;
416  const char* p_file;
417  long p_line;
418  int p_exit;
419 public:
420  cloudy_exit(const char* routine, const char* file, long line, int exit_code)
421  {
422  p_routine = routine;
423  p_file = file;
424  p_line = line;
425  p_exit = exit_code;
426  }
427  virtual ~cloudy_exit() throw()
428  {
429  p_routine = NULL;
430  p_file = NULL;
431  }
432  const char* routine() const throw()
433  {
434  return p_routine;
435  }
436  const char* file() const throw()
437  {
438  return p_file;
439  }
440  long line() const
441  {
442  return p_line;
443  }
444  int exit_status() const
445  {
446  return p_exit;
447  }
448 };
449 
450 // workarounds for __func__ are defined in cpu.h
451 #define cdEXIT( FAIL ) throw cloudy_exit( __func__, __FILE__, __LINE__, FAIL )
452 
453 // calls like puts( "[Stop in MyRoutine]" ) have been integrated in cdEXIT above
454 #define puts( STR ) Using_puts_before_cdEXIT_is_no_longer_needed
455 
457 void ShowMe(void);
458 
460 NORETURN void TotalInsanity(void);
461 
463 NORETURN void BadRead(void);
464 
466 NORETURN void BadOpen(void);
467 
472 NORETURN void NoNumb(char *chCard);
473 
477 int dbg_printf(int debug, const char *fmt, ...);
478 
480 int dprintf(FILE *fp, const char *format, ...);
481 
490 char *read_whole_line( char *chLine , int nChar , FILE *ioIN );
491 
492 /**************************************************************************
493  *
494  * various macros used by the code
495  *
496  **************************************************************************/
497 
501 #ifndef NDEBUG
502 # define DEBUG
503 #else
504 # undef DEBUG
505 #endif
506 
514 #ifndef PARALLEL_MODE
515 #define PARALLEL_MODE false
516 #endif
517 
519 #if defined(malloc)
520 /* ...but if malloc is a macro, assume it is instrumented by a memory debugging tool
521  * (e.g. dmalloc) */
522 # define MALLOC(exp) (malloc(exp))
523 #else
524 /* Otherwise instrument and protect it ourselves */
525 # define MALLOC(exp) (MyMalloc(exp,__FILE__, __LINE__))
526 #endif
527 
529 #if defined(calloc)
530 /* ...but if calloc is a macro, assume it is instrumented by a memory debugging tool */
531 # define CALLOC calloc
532 #else
533 /* Otherwise instrument and protect it ourselves */
534 # define CALLOC MyCalloc
535 #endif
536 
538 #if defined(realloc)
539 /* ...but if calloc is a macro, assume it is instrumented by a memory debugging tool */
540 # define REALLOC realloc
541 #else
542 /* Otherwise instrument and protect it ourselves */
543 # define REALLOC MyRealloc
544 #endif
545 
547 {
548  int p_sig;
549 public:
550  explicit bad_signal(int sig)
551  {
552  p_sig = sig;
553  }
554  virtual ~bad_signal() throw() {}
555  int sig() const throw()
556  {
557  return p_sig;
558  }
559 };
560 
562 {
563  const char* p_file;
564  long p_line;
565 public:
566  bad_assert(const char* file, long line)
567  {
568  p_file = file;
569  p_line = line;
570  }
571  virtual ~bad_assert() throw()
572  {
573  p_file = NULL;
574  }
575  const char* file() const throw()
576  {
577  return p_file;
578  }
579  long line() const throw()
580  {
581  return p_line;
582  }
583 };
584 
585 class bad_mpi {
587 public:
588  bad_mpi(long failMode) : p_failMode(failMode) {}
589  long failMode() const { return p_failMode; }
590 };
591 
593 #undef ASSERT
594 #ifndef STD_ASSERT
595 # ifdef NDEBUG
596 # define ASSERT(exp) ((void)0)
597 # elif defined ASSERTDEBUG
598 # define ASSERT(exp) if (!(exp)) MyAssert(__FILE__, __LINE__)
599 # else
600 /* the do { ... } while ( 0 ) prevents bugs in code like this:
601  * if( test )
602  * ASSERT( n == 10 );
603  * else
604  * do something else...
605  */
606 # define ASSERT(exp) \
607  do { \
608  if (!(exp)) \
609  { \
610  if( cpu.lgAssertAbort() ) \
611  abort(); \
612  else \
613  throw bad_assert(__FILE__,__LINE__); \
614  } \
615  } while( 0 )
616 # endif
617 #else
618 # define ASSERT(exp) (assert(exp))
619 #endif
620 
621 NORETURN inline void OUT_OF_RANGE(const char* str)
622 {
623  if( cpu.lgAssertAbort() )
624  abort();
625  else
626  throw out_of_range( str );
627 }
628 
629 /* Windows does not define isnan */
630 /* use our version on all platforms since the isnanf
631  * function does not exist under Solaris 9 either */
632 #undef isnan
633 #define isnan MyIsnan
634 
637 class t_debug : public Singleton<t_debug>
638 {
639  friend class Singleton<t_debug>;
640  FILE *p_fp;
642 protected:
644  {
645  p_fp = stderr;
646  p_callLevel = 0;
647  }
648 public:
649  void enter(const char *name)
650  {
651  ++p_callLevel;
652  fprintf(p_fp,"%*c%s\n",p_callLevel,'>',name);
653  }
654  void leave(const char *name)
655  {
656  fprintf(p_fp,"%*c%s\n",p_callLevel,'<',name);
657  --p_callLevel;
658  }
659 };
660 
661 template<bool lgTrace>
663 {
664  const char *p_name;
665 public:
666  explicit debugtrace(const char *funcname)
667  {
668  p_name = funcname;
669 # ifdef _MSC_VER
670  /* disable warning that conditional expression is constant, true or false in if */
671 # pragma warning( disable : 4127 )
672 # endif
673  if( lgTrace )
674  t_debug::Inst().enter(p_name);
675  }
677  {
678 # ifdef _MSC_VER
679  /* disable warning that conditional expression is constant, true or false in if */
680 # pragma warning( disable : 4127 )
681 # endif
682  if( lgTrace )
683  t_debug::Inst().leave(p_name);
684  p_name = NULL;
685  }
686  const char* name() const
687  {
688  return p_name;
689  }
690 };
691 
692 #ifdef DEBUG_FUN
693 #define DEBUG_ENTRY( funcname ) debugtrace<true> DEBUG_ENTRY( funcname )
694 #else
695 #ifdef __GNUC__
696 #define DEBUG_ENTRY( funcname ) ((void)0)
697 #else
698 #define DEBUG_ENTRY( funcname ) debugtrace<false> DEBUG_ENTRY( funcname )
699 #endif
700 #endif
701 
702 /* TorF(l) returns a 'T' or 'F' depending on the 'logical' expr 'l' */
703 inline char TorF( bool l ) { return l ? 'T' : 'F'; }
704 /* */
705 
707 inline bool is_odd( int j ) { return (j&1) == 1; }
708 inline bool is_odd( long j ) { return (j&1L) == 1L; }
709 /* */
710 
712 inline long nint( double x ) { return static_cast<long>( (x < 0.) ? x-0.5 : x+0.5 ); }
713 /* */
714 
715 /* define min for mixed arguments, the rest already exists */
716 inline long min( int a, long b ) { long c = a; return ( (c < b) ? c : b ); }
717 inline long min( long a, int b ) { long c = b; return ( (a < c) ? a : c ); }
718 inline double min( sys_float a, double b ) { double c = a; return ( (c < b) ? c : b ); }
719 inline double min( double a, sys_float b ) { double c = b; return ( (a < c) ? a : c ); }
720 
721 #undef MIN2
722 
723 #define MIN2 min
724 /* */
725 
726 #undef MIN3
727 
728 #define MIN3(a,b,c) (min(min(a,b),c))
729 /* */
730 
731 #undef MIN4
732 
733 #define MIN4(a,b,c,d) (min(min(a,b),min(c,d)))
734 /* */
735 
736 /* define max for mixed arguments, the rest already exists */
737 inline long max( int a, long b ) { long c = a; return ( (c > b) ? c : b ); }
738 inline long max( long a, int b ) { long c = b; return ( (a > c) ? a : c ); }
739 inline double max( sys_float a, double b ) { double c = a; return ( (c > b) ? c : b ); }
740 inline double max( double a, sys_float b ) { double c = b; return ( (a > c) ? a : c ); }
741 
742 #undef MAX2
743 
744 #define MAX2 max
745 /* */
746 
747 #undef MAX3
748 
749 #define MAX3(a,b,c) (max(max(a,b),c))
750 /* */
751 
752 #undef MAX4
753 
754 #define MAX4(a,b,c,d) (max(max(a,b),max(c,d)))
755 /* */
756 
761 template<class T>
762 inline T sign( T x, T y )
763 {
764  return ( y < T() ) ? -abs(x) : abs(x);
765 }
766 /* */
767 
769 template<class T>
770 inline int sign3( T x ) { return ( x < T() ) ? -1 : ( ( x > T() ) ? 1 : 0 ); }
771 /* */
772 
774 inline bool fp_equal( sys_float x, sys_float y, int n=3 )
775 {
776 # ifdef _MSC_VER
777  /* disable warning that conditional expression is constant, true or false in if */
778 # pragma warning( disable : 4127 )
779 # endif
780  ASSERT( n >= 1 );
781  // mimic IEEE behavior
782  if( isnan(x) || isnan(y) )
783  return false;
784  int sx = sign3(x);
785  int sy = sign3(y);
786  // treat zero cases first to avoid division by zero below
787  if( sx == 0 && sy == 0 )
788  return true;
789  // either x or y is zero (but not both), or x and y have different sign
790  if( sx*sy != 1 )
791  return false;
792  x = abs(x);
793  y = abs(y);
794  return ( 1.f - min(x,y)/max(x,y) < ((sys_float)n+0.1f)*FLT_EPSILON );
795 }
796 
797 inline bool fp_equal( double x, double y, int n=3 )
798 {
799  ASSERT( n >= 1 );
800  // mimic IEEE behavior
801  if( isnan(x) || isnan(y) )
802  return false;
803  int sx = sign3(x);
804  int sy = sign3(y);
805  // treat zero cases first to avoid division by zero below
806  if( sx == 0 && sy == 0 )
807  return true;
808  // either x or y is zero (but not both), or x and y have different sign
809  if( sx*sy != 1 )
810  return false;
811  x = abs(x);
812  y = abs(y);
813  return ( 1. - min(x,y)/max(x,y) < ((double)n+0.1)*DBL_EPSILON );
814 }
815 
816 inline bool fp_equal_tol( sys_float x, sys_float y, sys_float tol )
817 {
818  ASSERT( tol > 0.f );
819  // mimic IEEE behavior
820  if( isnan(x) || isnan(y) )
821  return false;
822  // make sure the tolerance is not too stringent
823  ASSERT( tol >= FLT_EPSILON*max(abs(x),abs(y)) );
824  return ( abs( x-y ) <= tol );
825 }
826 
827 inline bool fp_equal_tol( double x, double y, double tol )
828 {
829  ASSERT( tol > 0. );
830  // mimic IEEE behavior
831  if( isnan(x) || isnan(y) )
832  return false;
833  // make sure the tolerance is not too stringent
834  ASSERT( tol >= DBL_EPSILON*max(abs(x),abs(y)) );
835  return ( abs( x-y ) <= tol );
836 }
837 
838 #undef POW2
839 
840 #define POW2 pow2
841 template<class T>
842 inline T pow2(T a) { return a*a; }
843 /* */
844 
845 #undef POW3
846 
847 #define POW3 pow3
848 template<class T>
849 inline T pow3(T a) { return a*a*a; }
850 /* */
851 
852 #undef POW4
853 
854 #define POW4(X) (pow2(X)*pow2(X))
855 /* */
856 
857 #undef SDIV
858 
861 inline sys_float SDIV( sys_float x ) { return ( fabs((double)x) < (double)SMALLFLOAT ) ? (sys_float)SMALLFLOAT : x; }
862 /* \todo should we use SMALLDOUBLE here ? it produces overflows now... PvH */
863 inline double SDIV( double x ) { return ( fabs(x) < (double)SMALLFLOAT ) ? (double)SMALLFLOAT : x; }
864 // inline double SDIV( double x ) { return ( fabs(x) < SMALLDOUBLE ) ? SMALLDOUBLE : x; }
865 /* */
866 
871 {
872  // this should crash...
873  if( isnan(x) || isnan(y) )
874  return x/y;
875  int sx = sign3(x);
876  int sy = sign3(y);
877  // 0/0 -> NaN, this should crash as well...
878  if( sx == 0 && sy == 0 )
879  return x/y;
880  if( sx == 0 )
881  return 0.;
882  if( sy == 0 )
883  return ( sx < 0 ) ? -FLT_MAX : FLT_MAX;
884  // at this stage x != 0. and y != 0.
885  sys_float ay = abs(y);
886  if( ay >= 1.f )
887  return x/y;
888  else
889  {
890  // multiplication is safe since ay < 1.
891  if( abs(x) < ay*FLT_MAX )
892  return x/y;
893  else
894  return ( sx*sy < 0 ) ? -FLT_MAX : FLT_MAX;
895  }
896 }
897 
901 inline double safe_div(double x, double y)
902 {
903  // this should crash...
904  if( isnan(x) || isnan(y) )
905  return x/y;
906  int sx = sign3(x);
907  int sy = sign3(y);
908  // 0/0 -> NaN, this should crash as well...
909  if( sx == 0 && sy == 0 )
910  return x/y;
911  if( sx == 0 )
912  return 0.;
913  if( sy == 0 )
914  return ( sx < 0 ) ? -DBL_MAX : DBL_MAX;
915  // at this stage x != 0. and y != 0.
916  double ay = abs(y);
917  if( ay >= 1. )
918  return x/y;
919  else
920  {
921  // multiplication is safe since ay < 1.
922  if( abs(x) < ay*DBL_MAX )
923  return x/y;
924  else
925  return ( sx*sy < 0 ) ? -DBL_MAX : DBL_MAX;
926  }
927 }
928 
929 #undef HMRATE
930 /*HMRATE compile molecular rates using Hollenbach and McKee fits */
931 /* #define HMRATE(a,b,c) ( ((b) == 0 && (c) == 0) ? (a) : \
932  * ( ((c) == 0) ? (a)*pow(phycon.te/300.,(b)) : \
933  * ( ((c)/phycon.te > 50.) ? 0. : ( ((b) == 0) ? (a)*exp(-(c)/phycon.te) : \
934  * (a)*pow(phycon.te/300.,(b))*exp(-(c)/phycon.te) ) ) ) ) */
935 #define HMRATE(a,b,c) hmrate4(a,b,c,phycon.te)
936 
937 inline double hmrate4( double a, double b, double c, double te )
938 {
939  if( b == 0. && c == 0. )
940  return a;
941  else if( c == 0. )
942  return a*pow(te/300.,b);
943  else if( b == 0. )
944  return ( c/te <= 50. ) ? a*exp(-c/te) : 0.;
945  else
946  return ( c/te <= 50. ) ? a*pow(te/300.,b)*exp(-c/te) : 0.;
947 }
948 
949 template<class T>
950 inline void invalidate_array(T* p, size_t size)
951 {
952  memset( p, -1, size );
953 }
954 
955 inline void invalidate_array(double* p, size_t size)
956 {
957  set_NaN( p, (long)(size/sizeof(double)) );
958 }
959 
960 inline void invalidate_array(sys_float* p, size_t size)
961 {
962  set_NaN( p, (long)(size/sizeof(sys_float)) );
963 }
964 
990 template<class T>
991 class auto_vec
992 {
993  T* ptr;
994 
995  template<class U>
997  {
998  U* ptr;
999 
1000  explicit auto_vec_ref( U* p )
1001  {
1002  ptr = p;
1003  }
1004  };
1005 
1006 public:
1007  typedef T element_type;
1008 
1009  // 20.4.5.1 construct/copy/destroy:
1010 
1011  explicit auto_vec( element_type* p = NULL ) throw()
1012  {
1013  ptr = p;
1014  }
1015  auto_vec( auto_vec& p ) throw()
1016  {
1017  ptr = p.release();
1018  }
1019  auto_vec& operator= ( auto_vec& p ) throw()
1020  {
1021  reset( p.release() );
1022  return *this;
1023  }
1024  ~auto_vec() throw()
1025  {
1026  delete[] ptr;
1027  }
1028 
1029  // 20.4.5.2 members:
1030 
1031  element_type& operator[] ( ptrdiff_t n ) const throw()
1032  {
1033  return *(ptr+n);
1034  }
1035  element_type* get() const throw()
1036  {
1037  return ptr;
1038  }
1039  // for consistency with other container classes
1040  element_type* data() const throw()
1041  {
1042  return ptr;
1043  }
1044  element_type* release() throw()
1045  {
1046  element_type* p = ptr;
1047  ptr = NULL;
1048  return p;
1049  }
1050  void reset( element_type* p = NULL ) throw()
1051  {
1052  if( p != ptr )
1053  {
1054  delete[] ptr;
1055  ptr = p;
1056  }
1057  }
1058 
1059  // 20.4.5.3 conversions:
1060 
1062  {
1063  ptr = r.ptr;
1064  }
1065  auto_vec& operator= ( auto_vec_ref<element_type> r ) throw()
1066  {
1067  if( r.ptr != ptr )
1068  {
1069  delete[] ptr;
1070  ptr = r.ptr;
1071  }
1072  return *this;
1073  }
1074  operator auto_vec_ref<element_type>() throw()
1075  {
1076  return auto_vec_ref<element_type>( this->release() );
1077  }
1078 };
1079 
1080 #include "container_classes.h"
1081 
1082 /*Many structure were intoduced by Humeshkar B Nemala as a part of his Thesis
1083  *The structures were designed to read in transition,radiative and collisional data
1084  *from two major databases:LEIDEN and CHIANTI
1085 
1086  * these structures define the emission, collision, state, and transition classes*/
1087 
1088 typedef struct t_transition transition;
1090 typedef struct t_emission emission;
1091 typedef struct t_collision collision;
1092 typedef struct t_species species;
1093 
1095 {
1105 
1107  long int ipFine;
1108 
1123 
1135 
1142 
1145 
1148  double pump;
1149 
1151  double xIntensity;
1152 
1154  double phots;
1155 
1158 
1161 
1164 
1167 
1172 
1175 
1177  double ColOvTot;
1178 
1185 
1187  double PopOpc;
1188 
1191 
1193  double ots;
1194 
1195  /* this points back to the transition that points here. */
1197 
1198  /* linked-list */
1200 
1201 };
1202 
1203 /*The species structure is used to hold information about a particular atom,ion or molecule
1204 mentioned in the species.ini file.The name of the atom/ion/molecule is used to obtain the density
1205 of molecules in the case of the Leiden Database and along with atomic number and ion stage the
1206 density of atoms/ions in the case of the CHIANTI database */
1208 {
1209  /*Name of the atom/ion/ molecule*/
1211  /*Atomic Number*/
1212  int intAtNo;
1213  /*Ionization Stage*/
1215  /*Actual Number of energy levels in the data file*/
1217  /*Number of energy levels used locally*/
1219  /*Molecular weight*/
1221 
1222 
1223 };
1224 
1225 /*This structure is specifically used to hold the collision data in the format given in the LEIDEN Database
1226 The data is available as collsion rate coefficients(cm3 s-1) over different temperatures*/
1227 typedef struct t_CollRatesArray
1228 {
1229  /*Number of temps*/
1230  long ntemps;
1231  /*Array of temps*/
1232  double *temps;
1233  /*Matrix of collision rates(temp,up,lo)*/
1234  double ***collrates;
1235 
1237 
1238 /*This structure is specifically used to hold the collision data in the format given in the CHIANTI Database
1239 The data is available as spline fits to the maxwellian averaged collision strengths */
1240 typedef struct t_CollSplinesArray
1241 {
1242  /*Matrix of spline fits(hi,lo,spline index)*
1243  *The first five columns gives the no of spline pts,transition type,gf value,delta E
1244  *& Scaling parameter ,in the specified order*/
1245  /*The transition type basically tells how the temperature and collision
1246  strengths have been scaled*/
1247  double *collspline;
1248  double *SplineSecDer;
1249 
1250  long nSplinePts;
1252  double gf;
1253  double EnergyDiff;
1255 
1256 } CollSplinesArray ;
1257 
1259 {
1260  /* species *collider;*/
1261  /* Linked list for possible colliders */
1262  /* collision *next; */
1263 
1266 
1269 
1272 
1274  double cool , heat;
1275 
1276 };
1277 
1278 /*Generalized structure used to hold the energy level information for both atoms/ions and molecules*/
1280 {
1281  char chLabel[5];
1282  char chConfig[11];
1283 
1285 
1288 
1291 
1293  double Pop;
1294 
1296  int IonStg;
1298  int nelem;
1299 
1301  double ConBoltz;
1302 
1303  /* S is multiplicity. */
1304  long n, l, S, j;
1305 
1307  double lifetime;
1308 
1309  /* linked-list */
1311 };
1312 
1313 /*Generalized structure used to hold the transition information for both atoms/ions and molecules*/
1315 {
1319 
1320  /* Possible linked-list optimization */
1321  /*transition *nextemis, *nextcoll; */
1322 
1325 
1328 
1331 
1334 
1339  long ipCont;
1340 };
1341 
1342 /* Explicit instantiations for debugging purposes */
1345 
1346 
1347 /***************************************************************************
1348  *
1349  * a series of Cloudy service routines, used throughout code,
1350  *
1351  **************************************************************************/
1352 
1360 
1362 void Split(const string& str, // input string
1363  const string& sep, // separator, may be multiple characters
1364  vector<string>& lst, // the separated items will be appended here
1365  split_mode mode); // see above
1366 
1369 inline bool FindAndReplace(string& str,
1370  const string& substr,
1371  const string& newstr)
1372 {
1373  string::size_type ptr = str.find( substr );
1374  if( ptr != string::npos )
1375  str.replace( ptr, substr.length(), newstr );
1376  return ptr != string::npos;
1377 }
1378 
1381 inline bool FindAndErase(string& str,
1382  const string& substr)
1383 {
1384  return FindAndReplace( str, substr, "" );
1385 }
1386 
1392 double csphot(long int inu, long int ithr, long int iofset);
1393 
1398 double RandGauss(double xMean, double s );
1399 
1403 double MyGaussRand( double PctUncertainty );
1404 
1406 double AnuUnit(realnum energy);
1407 
1412 void cap4(char *chCAP , char *chLab);
1413 
1416 void uncaps(char *chCard );
1417 
1420 void caps(char *chCard );
1421 
1424 double e2(
1425  double t );
1426 
1429 double ee1(double x);
1430 
1434 double ee1_safe(double x);
1435 
1442 double FFmtRead(const char *chCard,
1443  long int *ipnt,
1444  long int last,
1445  bool *lgEOL);
1446 
1452 long nMatch(const char *chKey,
1453  const char *chCard);
1454 
1460 long int GetElem( char *chCARD_CAPS );
1461 
1470 int GetQuote(char *chLabel, char *chCard, bool lgABORT );
1471 
1472 /* want to define this only if no native os support exists */
1473 #if !HAVE_POWI
1474 
1475 double powi( double , long int );
1476 #endif
1477 
1480 long int ipow( long, long );
1481 
1484 void PrintE82( FILE*, double );
1485 
1487 void PrintE71( FILE*, double );
1488 
1490 void PrintE93( FILE*, double );
1491 
1497 char *PrintEfmt(const char *fmt, double val );
1498 
1500 const double SEXP_LIMIT = 84.;
1503 double sexp(double x);
1504 
1509 double dsexp(double x);
1510 
1515 double plankf(long int ip);
1516 
1523 double qg32( double, double, double(*)(double) );
1524 /* declar of optimize_func, the last arg, changed from double(*)() to above,
1525  * seemed to fix flags that were raised */
1526 
1527 
1537 void spsort( realnum x[], long int n, long int iperm[], int kflag, int *ier);
1538 
1539 /*vfun approximate form of Voigt function */
1540 inline double vfun(double damp, double x)
1541 {
1542  // constant is SQRTPI
1543  return sexp(x*x) + damp/1.772453850905516027298167/(1. + x*x);
1544 }
1545 
1546 /**************************************************************************
1547  *
1548  * disable some bogus errors in the ms c compiler
1549  *
1550  **************************************************************************/
1551 
1552 /* */
1553 #ifdef _MSC_VER
1554  /* disable warning that conditional expression is constant, true or false in if */
1555 # pragma warning( disable : 4127 )
1556  /* disable strcat warning */
1557 # pragma warning( disable : 4996 )
1558  /* disable bogus underflow warning in MS VS*/
1559 # pragma warning( disable : 4056 )
1560  /* disable "inline function removed since not used", MS VS*/
1561 # pragma warning( disable : 4514 )
1562  /* disable "assignment operator could not be generated", cddefines.h
1563  * line 126 */
1564 # pragma warning( disable : 4512 )
1565 #endif
1566 #ifdef __INTEL_COMPILER
1567 # pragma warning( disable : 1572 )
1568 #endif
1569 /* */
1570 
1571 /*lint +e129 these resolve several issues pclint has with my system headers */
1572 /*lint +e78 */
1573 /*lint +e830 */
1574 /*lint +e38 */
1575 /*lint +e148 */
1576 /*lint +e114 */
1577 /*lint +e18 */
1578 /*lint +e49 */
1579 
1580 #endif /* _CDDEFINES_H_ */
1581 

Generated for cloudy by doxygen 1.8.1.2