49 #if defined(PRINT_DR) || defined(PRINT_RR) 
   50 static const char FILE_NAME_OUT[] = 
"array.out";
 
   60         long int atomic_number,
 
   62         long int ionic_charge,
 
   73         ASSERT( ionic_charge > 0 );
 
   76         const double mu = 0.000;        
 
   77         const double w = 5.64586;       
 
   78         const double x_a0 = 10.1821;    
 
   84         const double c = 10.0;  
 
   86         double s, snew, x_a, E_c;
 
   88         long int iso_sequence, N_1, N_2;
 
   91         double Tlog = log10(T);
 
   94         iso_sequence = atomic_number - ionic_charge;
 
   95         ASSERT( iso_sequence > 0 );
 
   98         double ionchar = double(ionic_charge) / 10.;
 
  103         if( (iso_sequence >= 1) && (iso_sequence <= 2) )       
 
  108         else if( (iso_sequence >= 3) && (iso_sequence <= 10) ) 
 
  113         else if( (iso_sequence >= 11) && (iso_sequence <= 18) ) 
 
  118         else if( (iso_sequence >= 19) && (iso_sequence <= 36) ) 
 
  123         else if( (iso_sequence >= 37) && (iso_sequence <= 54) ) 
 
  128         else if( (iso_sequence >= 55) && (iso_sequence <= 86) ) 
 
  133         else if( iso_sequence >= 87 )                           
 
  146         A_N = 12.0 + 10.0 * N_1 + (10.0 * N_1 - 2.0 * N_2) * (iso_sequence - N_1) / (N_1 - N_2);
 
  154         if( iso_sequence == 1 )      
 
  159         else if( iso_sequence == 2 ) 
 
  164         else if( iso_sequence == 3 ) 
 
  166                 E_c = 1.96274 + ionchar*(20.30014 + ionchar*(-0.97103 + ionchar*( 0.85453 + ionchar*( 0.13547 + 0.02401*ionchar))));
 
  169         else if( iso_sequence == 4 ) 
 
  171                 E_c = 5.78908 + ionchar*(34.08270 + ionchar*( 1.51729 + ionchar*(-1.21227 + ionchar*( 0.77559 - 0.00410*ionchar))));
 
  174         else if( iso_sequence == 5 ) 
 
  179         else if( iso_sequence == 7 ) 
 
  181                 E_c = 11.37092 + ionchar*(36.22053 + ionchar*( 7.08448 + ionchar*(-5.16840 + ionchar*( 2.45056 - 0.16961*ionchar))));
 
  183         else if( iso_sequence == 11 ) 
 
  185                 E_c =  2.24809 + ionchar*(22.27768 + ionchar*(-1.12285 + ionchar*( 0.90267 + ionchar*(-0.03860 + 0.01468*ionchar))));
 
  187         else if( iso_sequence == 12 )          
 
  189                 E_c =  2.74508 + ionchar*(19.18623 + ionchar*(-0.54317 + ionchar*( 0.78685 + ionchar*(-0.04249 + 0.01357*ionchar))));
 
  191         else if( iso_sequence == 15 ) 
 
  193                 E_c =  1.42762 + ionchar*( 3.90778 + ionchar*( 0.73119 + ionchar*(-1.91404 + ionchar*( 1.05059 - 0.08992*ionchar))));
 
  201         if( iso_sequence == 16 && ionchar==2 )
 
  204         double xic = double(ionic_charge);
 
  207         if( iso_sequence <= 5 ) 
 
  209                 double pp1,pp2,pp3,pp4,pp5,pp6,AN0; 
 
  211                 double Tscal = T/
pow2(xic);
 
  212                 A_N *= 2.0 / ( 1.0 + exp(-sqrt(25000.0 / Tscal)));  
 
  214                 if( iso_sequence == 1 ) 
 
  216                         pp1 =  4.7902  + 0.32456 * 
pow(xic, 0.97838) * exp( -xic /  24.78084 ); 
 
  217                         pp2 = -0.0327  + 0.13265 * 
pow(xic, 0.29226);                           
 
  218                         pp3 = -0.66855 + 0.28711 * 
pow(xic, 0.29083) * exp( -xic /   6.65275 ); 
 
  219                         pp4 =  6.23776 + 0.11389 * 
pow(xic, 1.24036) * exp( -xic /  25.79559 ); 
 
  220                         pp5 =  0.33302 + 0.00654 * 
pow(xic, 5.67945) * exp( -xic /   0.92602 ); 
 
  221                         pp6 = -0.75788 + 1.75669 * 
pow(xic,-0.63105) * exp( -xic / 184.82361 ); 
 
  223                 else if( iso_sequence == 2 ) 
 
  225                         pp1 =  4.82857 + 0.3     * 
pow(xic, 1.04558) * exp( -xic / 19.6508  ); 
 
  226                         pp2 = -0.50889 + 0.6     * 
pow(xic, 0.17187) * exp( -xic / 47.19496 ); 
 
  227                         pp3 = -1.03044 + 0.35    * 
pow(xic, 0.3586 ) * exp( -xic / 39.4083  ); 
 
  228                         pp4 =  6.14046 + 0.15    * 
pow(xic, 1.46561) * exp( -xic / 10.17565 ); 
 
  229                         pp5 =  0.08316 + 0.08    * 
pow(xic, 1.37478) * exp( -xic /  8.54111 ); 
 
  230                         pp6 = -0.19804 + 0.4     * 
pow(xic, 0.74012) * exp( -xic /  2.54024 ); 
 
  232                 else if( iso_sequence == 3 ) 
 
  234                         pp1 =  4.55441 + 0.08    * 
pow(xic, 1.11864);                          
 
  235                         pp2 =  0.3     + 2.0     * 
powi(xic, -2)     * exp( -xic / 67.36368 ); 
 
  236                         pp3 = -0.4     + 0.38    * 
pow(xic, 1.62248) * exp( -xic /  2.78841 ); 
 
  237                         pp4 =  4.00192 + 0.58    * 
pow(xic, 0.93519) * exp( -xic / 21.28094 ); 
 
  238                         pp5 =  0.00198 + 0.32    * 
pow(xic, 0.84436) * exp( -xic /  9.73494 ); 
 
  239                         pp6 =  0.55031 - 0.32251 * 
pow(xic, 0.75493) * exp( -xic / 19.89169 ); 
 
  241                 else if( iso_sequence == 4 ) 
 
  243                         pp1 =  2.79861 + 1.0     * 
pow(xic, 0.82983) * exp( -xic / 18.05422 ); 
 
  244                         pp2 = -0.01897 + 0.05    * 
pow(xic, 1.34569) * exp( -xic / 10.82096 ); 
 
  245                         pp3 = -0.56934 + 0.68    * 
pow(xic, 0.78839) * exp( -xic /  2.77582 ); 
 
  246                         pp4 =  4.07101 + 1.0     * 
pow(xic, 0.7175 ) * exp( -xic / 25.89966 ); 
 
  247                         pp5 =  0.44352 + 0.05    * 
pow(xic, 3.54877) * exp( -xic /  0.94416 ); 
 
  248                         pp6 = -0.57838 + 0.68    * 
pow(xic, 0.08484) * exp( -xic /  6.70076 ); 
 
  250                 else if( iso_sequence == 5 ) 
 
  252                         pp1 =  6.75706 - 3.77435 *                     exp( -xic /  4.59785 ); 
 
  253                         pp2 =  0.0     + 0.08    * 
pow(xic, 1.34923) * exp( -xic /  7.36394 ); 
 
  254                         pp3 = -0.63    + 0.06    * 
pow(xic, 2.65736) * exp( -xic /  2.11946 ); 
 
  255                         pp4 =  7.74115 - 4.82142 *                     exp( -xic /  4.04344 ); 
 
  256                         pp5 =  0.26595 + 0.09    * 
pow(xic, 1.29301) * exp( -xic /  6.81342 ); 
 
  257                         pp6 = -0.39209 + 0.07    * 
pow(xic, 2.27233) * exp( -xic /  1.9958  ); 
 
  264                 AN0 = pp3 * exp( -0.5*
pow2((Tlog - pp1)/pp2) ) + pp6 * exp( -0.5*
pow2((Tlog - pp4)/pp5) );
 
  276         double gg1,gg2,gg3,gg4,gg5,gg6,BN0=0.; 
 
  278         if( iso_sequence == 5 ) 
 
  281                 gg1 =  6.91078 - 1.6385  * 
pow(xic, 2.18197) * exp( -xic / 1.45091 ); 
 
  282                 gg2 =  0.4959  - 0.08348 * 
pow(xic, 1.24745) * exp( -xic / 8.55397 ); 
 
  283                 gg3 = -0.27525 + 0.132   * 
pow(xic, 1.15443) * exp( -xic / 3.79949 ); 
 
  284                 gg4 =  7.45975 - 2.6722  * 
pow(xic, 1.7423 ) * exp( -xic / 1.19649 ); 
 
  285                 gg5 =  0.51285 - 0.60987 * 
pow(xic, 5.15431) * exp( -xic / 0.49095 ); 
 
  286                 gg6 = -0.24818 + 0.125   * 
pow(xic, 0.59971) * exp( -xic / 8.34052 ); 
 
  288         else if( iso_sequence == 6 ) 
 
  290                 gg1 =  5.90184 - 1.2997  * 
pow(xic, 1.32018) * exp( -xic /  2.10442 ); 
 
  291                 gg2 =  0.12606 + 0.009   * 
pow(xic, 8.33887) * exp( -xic /  0.44742 ); 
 
  292                 gg3 = -0.28222 + 0.018   * 
pow(xic, 2.50307) * exp( -xic /  3.83303 ); 
 
  293                 gg4 =  6.96615 - 0.41775 * 
pow(xic, 2.75045) * exp( -xic /  1.32394 ); 
 
  294                 gg5 =  0.55843 + 0.45    *                     exp( -xic /  2.06664 ); 
 
  295                 gg6 = -0.17208 - 0.17353 *                     exp( -xic /  2.57406 ); 
 
  297         else if( iso_sequence == 13 ) 
 
  299                 gg1 =  6.59628 - 3.03115 *                     exp( -xic / 10.519821 ); 
 
  300                 gg2 =  1.20824 - 0.85509 * 
pow(xic, 0.21258) * exp( -xic / 25.56     ); 
 
  301                 gg3 = -0.34292 - 0.06013 * 
pow(xic, 4.09344) * exp( -xic /  0.90604  ); 
 
  302                 gg4 =  7.92025 - 3.38912 *                     exp( -xic / 10.02741  ); 
 
  303                 gg5 =  0.06976 + 0.6453  * 
pow(xic, 0.24827) * exp( -xic / 20.94907  ); 
 
  304                 gg6 = -0.34108 - 0.17353 *                     exp( -xic /  6.0384   ); 
 
  306         else if( iso_sequence == 14 ) 
 
  308                 gg1 =  5.54172 - 1.54639 * 
pow(xic, 0.01056) * exp( -xic /  3.24604  ); 
 
  309                 gg2 =  0.39649 + 0.8     * 
pow(xic, 3.19571) * exp( -xic /  0.642068 ); 
 
  310                 gg3 = -0.35475 - 0.08912 * 
pow(xic, 3.55401) * exp( -xic /  0.73491  ); 
 
  311                 gg4 =  6.88765 - 1.93088 * 
pow(xic, 0.23469) * exp( -xic /  3.23495  ); 
 
  312                 gg5 =  0.58577 - 0.31007 * 
pow(xic, 3.30137) * exp( -xic /  0.83096  ); 
 
  313                 gg6 = -0.14762 - 0.16941 *                     exp( -xic / 18.53007  ); 
 
  324         if( gg3 != 0. || gg6 != 0. )
 
  327                 BN0 = gg3 * exp( -0.5*
pow2((Tlog - gg1)/gg2) ) + gg6 * exp( -0.5*
pow2((Tlog - gg4)/gg5) );
 
  333                 fprintf(
ioQQQ, 
"DEBUGDN an=%li q=%li logNe=%.2e Te=%.2e N_1=%li N_2=%li Niso=%li BN0=%.2e\n",   
 
  334                         atomic_number, ionic_charge, eden, T ,
 
  335                         N_1 , N_2 , iso_sequence, BN0);
 
  342         q_0 = 1.0 / sqrt((
double)ionic_charge);
 
  343         q_0 = A_N * q_0 * (1.0 - 0.816497 * q_0);
 
  347         T_0 = 50000.0 * 
pow2( q_0 );
 
  350         x_a = x_a0 + log10( 
powi( ((
double)ionic_charge/q_0), 7 ) * sqrt( T/T_0 ) );
 
  360                 s = ( mu/( 1. + 
pow2((eden-x_a)/w) ) +
 
  361                     (1. - mu) * exp( -LN_TWO * 
pow2((eden-x_a)/w) ) );
 
  370         snew = 1. + (s-1.)*exp(-(E_c*EVDEGK)/(c*T));
 
  372         ASSERT( snew >= 0. && snew <= 1. );
 
  391         int nAtomicNumberCScale, 
 
  393         int n_core_e_before_recomb )
 
  396         double RateCoefficient, sum;
 
  400         ASSERT( nAtomicNumberCScale>=0 && nAtomicNumberCScale<
LIMELM );
 
  402         if( nAtomicNumberCScale==
ipIRON && n_core_e_before_recomb>=12 && 
 
  403                 n_core_e_before_recomb<=18 )
 
  412                 static const double cFe_q[7][8] =
 
  414                         {5.636e-4, 7.390e-3, 3.635e-2, 1.693e-1, 3.315e-2, 2.288e-1, 7.316e-2, 0.},
 
  415                         {1.090e-3, 7.801e-3, 1.132e-2, 4.740e-2, 1.990e-1, 3.379e-2, 1.140e-1, 1.250e-1},
 
  416                         {3.266e-3, 7.637e-3, 1.005e-2, 2.527e-2, 6.389e-2, 1.564e-1, 0.,       0.},
 
  417                         {1.074e-3, 6.080e-3, 1.887e-2, 2.540e-2, 7.580e-2, 2.773e-1, 0.,       0.},
 
  418                         {9.073e-4, 3.777e-3, 1.027e-2, 3.321e-2, 8.529e-2, 2.778e-1, 0.,       0.},
 
  419                         {5.335e-4, 1.827e-3, 4.851e-3, 2.710e-2, 8.226e-2, 3.147e-1, 0.,       0.},
 
  420                         {7.421e-4, 2.526e-3, 4.605e-3, 1.489e-2, 5.891e-2, 2.318e-1, 0.,       0.}
 
  424                 static const double EFe_q[7][8] =
 
  426                         {3.628e3, 2.432e4, 1.226e5, 4.351e5, 1.411e6, 6.589e6, 1.030e7, 0},
 
  427                         {1.246e3, 1.063e4, 4.719e4, 1.952e5, 5.637e5, 2.248e6, 7.202e6, 3.999e9},
 
  428                         {1.242e3, 1.001e4, 4.466e4, 1.497e5, 3.919e5, 6.853e5, 0.     , 0.},
 
  429                         {1.387e3, 1.048e4, 3.955e4, 1.461e5, 4.010e5, 7.208e5, 0.     , 0.},
 
  430                         {1.525e3, 1.071e4, 4.033e4, 1.564e5, 4.196e5, 7.580e5, 0.     , 0.},
 
  431                         {2.032e3, 1.018e4, 4.638e4, 1.698e5, 4.499e5, 7.880e5, 0.     , 0.},
 
  432                         {3.468e3, 1.353e4, 3.690e4, 1.957e5, 4.630e5, 8.202e5, 0.     , 0.}
 
  435                 long int nion = n_core_e_before_recomb - 12;
 
  436                 ASSERT( nion>=0 && nion <=6 );
 
  440                 for( i=0; i < 8; ++i )
 
  442                         sum += (cFe_q[nion][i] * 
sexp( EFe_q[nion][i]/
phycon.
te));
 
  447                 strcpy(
chDRDataSource[nAtomicNumberCScale][nAtomicNumberCScale-n_core_e_before_recomb] ,
 
  450                 return RateCoefficient;
 
  454         else if( nAtomicNumberCScale < n_core_e_before_recomb )
 
  456                 RateCoefficient = -2;
 
  459         else if( nAtomicNumberCScale >= 
LIMELM )
 
  461                 RateCoefficient = -2;
 
  466                 RateCoefficient = -1;
 
  473                 for(i=0; i<
nDRFitPar[nAtomicNumberCScale][n_core_e_before_recomb]; ++i  )
 
  475                         sum += (
DRFitParPart1[nAtomicNumberCScale][n_core_e_before_recomb][i] *
 
  479                 strcpy(
chDRDataSource[nAtomicNumberCScale][nAtomicNumberCScale-n_core_e_before_recomb] ,
 
  488                 RateCoefficient = -99;
 
  491         ASSERT( RateCoefficient < 1e-6 );
 
  493         return RateCoefficient;
 
  502                         int nAtomicNumberCScale, 
 
  504                         int n_core_e_before_recomb )
 
  506         double RateCoefficient;
 
  511         ASSERT( nAtomicNumberCScale>=0 && nAtomicNumberCScale<
LIMELM );
 
  513         if( nAtomicNumberCScale==
ipIRON && 
 
  514                 n_core_e_before_recomb>=12 && n_core_e_before_recomb<=18 )
 
  523                 static const double parFeq[7][6] ={
 
  524                         {1.179e-9 , 0.7096, 4.508e2, 3.393e7, 0.0154, 3.977e6},
 
  525                         {1.050e-9 , 0.6939, 4.568e2, 3.987e7, 0.0066, 5.451e5},
 
  526                         {9.832e-10, 0.7146, 3.597e2, 3.808e7, 0.0045, 3.952e5},
 
  527                         {8.303e-10, 0.7156, 3.531e2, 3.554e7, 0.0132, 2.951e5},
 
  528                         {1.052e-9 , 0.7370, 1.639e2, 2.924e7, 0.0224, 4.291e5},
 
  529                         {1.338e-9 , 0.7495, 7.242e1, 2.453e7, 0.0404, 4.199e5},
 
  530                         {1.263e-9 , 0.7532, 5.209e1, 2.169e7, 0.0421, 2.917e5}
 
  535                 long int nion = n_core_e_before_recomb - 12;
 
  536                 ASSERT( nion>=0 && nion <=6 );
 
  539                 B = parFeq[nion][1] + parFeq[nion][4]*exp(temp);
 
  540                 D = sqrt(
phycon.
te/parFeq[nion][2]); 
 
  541                 F = sqrt(
phycon.
te/parFeq[nion][3]); 
 
  542                 RateCoefficient = parFeq[nion][0]/(D*
pow((1.+D),(1.-B))*
pow((1.+F),(1.+B)));
 
  543                 strcpy(
chRRDataSource[nAtomicNumberCScale][nAtomicNumberCScale-n_core_e_before_recomb] ,
"Bad06");
 
  545                 return RateCoefficient;
 
  549         else if( nAtomicNumberCScale < n_core_e_before_recomb )
 
  551                 RateCoefficient = -2;
 
  554         else if( nAtomicNumberCScale >= 
LIMELM )
 
  556                 RateCoefficient = -2;
 
  561                 RateCoefficient = -1;
 
  572                 B = 
RRFitPar[nAtomicNumberCScale][n_core_e_before_recomb][1] + 
 
  573                         RRFitPar[nAtomicNumberCScale][n_core_e_before_recomb][4]*exp(temp);
 
  574                 D = sqrt(
phycon.
te/
RRFitPar[nAtomicNumberCScale][n_core_e_before_recomb][2]); 
 
  575                 F = sqrt(
phycon.
te/
RRFitPar[nAtomicNumberCScale][n_core_e_before_recomb][3]); 
 
  576                 RateCoefficient = 
RRFitPar[nAtomicNumberCScale][n_core_e_before_recomb][0]/(D*
pow((1.+D),(1.-B))*
pow((1.+F),(1.+B)));
 
  577                 strcpy(
chRRDataSource[nAtomicNumberCScale][nAtomicNumberCScale-n_core_e_before_recomb] ,
"Bad06");
 
  582                 RateCoefficient = -99;
 
  584         return RateCoefficient;
 
  597         int NuclearCharge=-1, NumberElectrons=-1;
 
  600         int M_state, W_state;
 
  602         const int NBLOCK = 2;
 
  603         int data_begin_line[NBLOCK];
 
  606         const char* chFilename;
 
  610         const int BIGGEST_INDEX_TO_USE = 103;
 
  613         long TheirIndexToOurIndex[BIGGEST_INDEX_TO_USE];
 
  618         long INDX=0,INDP=0,
N=0,
S=0,L=0,J=0,maxINDX=0,loopindex=0,max_N_of_data=-1;
 
  621         static int nCalled = 0;
 
  623         static const char* cdDATAFILE[] = 
 
  627                 "UTA/nrb00_h_he1ic12.dat",
 
  628                 "UTA/nrb00_h_li2ic12.dat",
 
  629                 "UTA/nrb00_h_be3ic12.dat",
 
  630                 "UTA/nrb00_h_b4ic12.dat",
 
  631                 "UTA/nrb00_h_c5ic12.dat",
 
  632                 "UTA/nrb00_h_n6ic12.dat",
 
  633                 "UTA/nrb00_h_o7ic12.dat",
 
  634                 "UTA/nrb00_h_f8ic12.dat",
 
  635                 "UTA/nrb00_h_ne9ic12.dat",
 
  636                 "UTA/nrb00_h_na10ic12.dat",
 
  637                 "UTA/nrb00_h_mg11ic12.dat",
 
  638                 "UTA/nrb00_h_al12ic12.dat",
 
  639                 "UTA/nrb00_h_si13ic12.dat",
 
  640                 "UTA/nrb00_h_p14ic12.dat",
 
  641                 "UTA/nrb00_h_s15ic12.dat",
 
  642                 "UTA/nrb00_h_cl16ic12.dat",
 
  643                 "UTA/nrb00_h_ar17ic12.dat",
 
  644                 "UTA/nrb00_h_k18ic12.dat",
 
  645                 "UTA/nrb00_h_ca19ic12.dat",
 
  646                 "UTA/nrb00_h_sc20ic12.dat",
 
  647                 "UTA/nrb00_h_ti21ic12.dat",
 
  648                 "UTA/nrb00_h_v22ic12.dat",
 
  649                 "UTA/nrb00_h_cr23ic12.dat",
 
  650                 "UTA/nrb00_h_mn24ic12.dat",
 
  651                 "UTA/nrb00_h_fe25ic12.dat",
 
  652                 "UTA/nrb00_h_co26ic12.dat",
 
  653                 "UTA/nrb00_h_ni27ic12.dat",
 
  654                 "UTA/nrb00_h_cu28ic12.dat",
 
  655                 "UTA/nrb00_h_zn29ic12.dat" 
  668 #       if defined(PRINT_DR) || defined(PRINT_RR) 
  669         FILE *ofp = 
open_data( FILE_NAME_OUT, 
"w" );
 
  674                 for( 
long nelem=ipISO; nelem < 
LIMELM; nelem++ )
 
  681                                                 iso_sp[ipISO][nelem].fb[ipHi].DielecRecombVsTemp[k] = 0.;
 
  693                         ioDATA= 
open_data( cdDATAFILE[nelem], 
"r" );
 
  698                         for( 
long i=0; i<BIGGEST_INDEX_TO_USE; i++ )
 
  699                                 TheirIndexToOurIndex[i] = -1;
 
  706                                         if( 
nMatch(
"INDX  INDP ",
string) )
 
  711                                                         fprintf( 
ioQQQ, 
" Badnell data file appears to be corrupted.\n");
 
  718                                                         if( strcmp(
string,
"\n")==0 )
 
  725                                                         INDX=(long)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  726                                                         if( INDX >= BIGGEST_INDEX_TO_USE )
 
  733                                                         ASSERT( INDX < BIGGEST_INDEX_TO_USE );                                                                   
 
  735                                                         INDP=(long)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  740                                                                 if( (i1=
nMatch(
"1S1 ",
string)) > 0 )
 
  743                                                                         N=(long)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  751                                                                 if( (i1=
nMatch(
"     (",
string)) > 0 )
 
  754                                                                         S=(long)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  765                                                                 L=(long)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  770                                                                 J=(long)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  771                                                                 ASSERT( J <= ( L + (
int)((
S+1)/2) ) && 
 
  772                                                                         J >= ( L - (
int)((
S+1)/2) ) && J >= 0 );
 
  787                                                                 if( 
N==2 && L==1 && 
S==3 )
 
  790                                                                                 TheirIndexToOurIndex[INDX] = 3;
 
  792                                                                                 TheirIndexToOurIndex[INDX] = 4;
 
  796                                                                                 ASSERT( TheirIndexToOurIndex[INDX] == 5 );
 
  799                                                                 max_N_of_data = 
MAX2( max_N_of_data, 
N );
 
  818                         ASSERT( maxINDX < BIGGEST_INDEX_TO_USE );
 
  827                                         if( 
nMatch(
"INDX TE= ",
string) )
 
  834                                                         fprintf( 
ioQQQ, 
" Badnell data file appears to be corrupted.\n");
 
  842                                                         if( 
nMatch(
"PRTF",
string) || INDX >= maxINDX || INDX<0 )
 
  846                                                         INDX=(long)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  852                                                         if( TheirIndexToOurIndex[INDX] < 
iso_sp[
ipHE_LIKE][nelem].numLevels_max && 
 
  853                                                                 TheirIndexToOurIndex[INDX] > 0 )
 
  858                                                         for(loopindex=0;loopindex<10;loopindex++)
 
  860                                                                 value=(double)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  867                                                                 fprintf( 
ioQQQ, 
" Badnell data file appears to be corrupted.\n");
 
  873                                                         for(loopindex=10;loopindex<19;loopindex++)
 
  875                                                                 value=(double)
FFmtRead(
string,&i1,
sizeof(
string),&lgEOL);
 
  886                         ASSERT( maxINDX < BIGGEST_INDEX_TO_USE );
 
  887                         ASSERT( max_N_of_data > 0 );
 
  896                                 for( 
long i=TheirIndexToOurIndex[maxINDX]+1; 
 
  907                                         for(loopindex=0;loopindex<19;loopindex++)
 
  923                                         for(loopindex=0;loopindex<19;loopindex++)
 
  935         for( 
long i=0; i<NBLOCK; ++i )
 
  938                 data_begin_line[i] = INT_MIN;
 
  941         chFilename = 
"badnell_dr.dat";
 
  957                         data_begin_line[number] = count;
 
  958                         ASSERT( number < NBLOCK );
 
  977         for( 
long nelem=0; nelem<
LIMELM; nelem++ )
 
  991                 for( 
long ion=0; ion<nelem+1; ++ion )
 
 1019         fseek(ioDATA, 0, SEEK_SET);
 
 1021         if( 
read_whole_line( chLine , (
int)
sizeof(chLine) , ioDATA ) == NULL )
 
 1023                 fprintf( 
ioQQQ, 
" DISASTER PROBLEM Badnell_rec_init could not read first line of badnell_dr.dat.\n");
 
 1029         if( (chs = 
strchr_s(chLine, 
')'))==NULL )
 
 1032                 fprintf( 
ioQQQ, 
" DISASTER PROBLEM Badnell_rec_init data file incorrect format.\n");
 
 1037         sscanf(chs, 
"%4i%2i%2i",&yr, &mo, &dy);
 
 1039         int dr_yr = 2012, dr_mo = 6, dr_dy = 28;
 
 1040         if((yr != dr_yr) || (mo != dr_mo) || (dy != dr_dy))
 
 1043                         "DISASTER PROBLEM Badnell_rec_init The version of %s I found (%i %i %i) is not the current version (%i %i %i).\n",
 
 1044                         chFilename, yr, mo, dy, dr_yr, dr_mo, dr_dy);
 
 1045                 fprintf(
ioQQQ,
" The first line of the file is the following\n %s\n", chLine );
 
 1052                 length_of_line = (int)strlen(chLine);
 
 1055                 if( count > data_begin_line[0] && count < data_begin_line[1] && length_of_line >3 )
 
 1062                         sscanf(chLine, 
"%i%i%i%i%lf%lf%lf%lf%lf%lf%lf%lf%lf",
 
 1063                                 &NuclearCharge, &NumberElectrons, &M_state, &W_state, &par_C[0], &par_C[1], &par_C[2],
 
 1064                                 &par_C[3], &par_C[4], &par_C[5], &par_C[6], &par_C[7], &par_C[8]);
 
 1067                         long int NuclearChargeM1 = NuclearCharge-1;
 
 1069                         if(M_state == 1 && NuclearChargeM1 < LIMELM )
 
 1072                                 ASSERT( NumberElectrons < LIMELM );
 
 1073                                 ASSERT( NuclearChargeM1 < LIMELM );
 
 1077                                 nDRFitPar[NuclearChargeM1][NumberElectrons] = 9;
 
 1078                                 for( 
long i=8; i>=0; i-- )
 
 1081                                                 --
nDRFitPar[NuclearChargeM1][NumberElectrons];
 
 1087                                 for( 
long i=0; i<9; i++ )
 
 1088                                         DRFitParPart1[NuclearChargeM1][NumberElectrons][i] = par_C[i];
 
 1094         fseek(ioDATA, 0, SEEK_SET);
 
 1099                 length_of_line = (int)strlen(chLine);
 
 1100                 if( count > data_begin_line[1] && length_of_line > 3 )
 
 1108                         sscanf(chLine, 
"%i%i%i%i%lf%lf%lf%lf%lf%lf%lf%lf%lf",
 
 1109                                 &NuclearCharge, &NumberElectrons, &M_state, &W_state, &par_E[0], &par_E[1], &par_E[2],
 
 1110                                 &par_E[3], &par_E[4], &par_E[5], &par_E[6], &par_E[7], &par_E[8]);
 
 1112                         long int NuclearChargeM1 = NuclearCharge-1;
 
 1114                         if(M_state == 1 && NuclearChargeM1<LIMELM)
 
 1116                                 ASSERT( NumberElectrons < LIMELM );
 
 1117                                 ASSERT( NuclearChargeM1 < LIMELM );
 
 1121                                 nDRFitPar[NuclearChargeM1][NumberElectrons] = 9;
 
 1122                                 for( 
long i=8; i>=0; i-- )
 
 1125                                                 --
nDRFitPar[NuclearChargeM1][NumberElectrons];
 
 1131                                 for( 
long i=0; i<
nDRFitPar[NuclearChargeM1][NumberElectrons]; i++ )
 
 1132                                         DRFitParPart2[NuclearChargeM1][NumberElectrons][i] = par_E[i];
 
 1141         for( 
long nelem=0; nelem<
LIMELM; nelem++ )
 
 1143                 for( 
int ion=0; ion<nelem+1;++ion )
 
 1147                                 fprintf(ofp, 
"%i %i %e %e %e %e %e %e %e %e %e\n",
 
 1156         for( 
long nelem=0; nelem<
LIMELM; nelem++ )
 
 1158                 for( 
int ion=0; ion<nelem+1; ion++ )
 
 1162                                 fprintf(ofp, 
"%i %i %e %e %e %e %e %e %e %e %e\n",
 
 1176         bool lgDRBadnellBothDefined = 
true;
 
 1177         for( 
int nelem=0; nelem<
LIMELM; nelem++ )
 
 1179                 for( 
int ion=0; ion<nelem+1; ion++ )
 
 1188                                 fprintf( 
ioQQQ, 
"PROBLEM ion_recomb_Badnell first and second half of Badnell DR not consistent.\n");
 
 1189                                 lgDRBadnellBothDefined = 
false;
 
 1194         if( !lgDRBadnellBothDefined )
 
 1198                         "DISASTER PROBLEM The DR data files are corrupted - part 1 and 2 do not agree.\n");
 
 1199                 fprintf(
ioQQQ,
" Start again with a fresh copy of the data directory\n" );
 
 1204         chFilename = 
"badnell_rr.dat";
 
 1209                 if( 
read_whole_line( chLine , (
int)
sizeof(chLine) , ioDATA ) == NULL )
 
 1211                         fprintf( 
ioQQQ, 
" DISASTER PROBLEM Badnell_rec_init could not read first line of badnell_rr.dat.\n");
 
 1215                 if( (chs = 
strchr_s(chLine, 
')'))==NULL )
 
 1218                         fprintf( 
ioQQQ, 
" DISASTER PROBLEM Badnell_rec_init data file incorrect format.\n");
 
 1222                 sscanf(chs, 
"%4i%2i%2i", &yr, &mo, &dy);
 
 1223                 int rr_yr = 2011, rr_mo = 4, rr_dy = 12;
 
 1224                 if((yr != rr_yr)||(mo != rr_mo)||(dy != rr_dy))
 
 1226                         fprintf(
ioQQQ,
"DISASTER PROBLEM The version of %s I found (%i %i %i) is not the current version (%i %i %i).\n",
 
 1227                                 chFilename, yr, mo, dy, rr_yr, rr_mo, rr_dy);
 
 1228                         fprintf(
ioQQQ,
" The line was as follows:\n %s\n", chLine );
 
 1240                 if(chLine[0] != 
'#')
 
 1242                         sscanf(chLine, 
"%i%i%i%i%lf%lf%lf%lf%lf%lf",
 
 1243                                 &NuclearCharge, &NumberElectrons, &M_state, &W_state, &temp_par[0], &temp_par[1],
 
 1244                                 &temp_par[2], &temp_par[3], &temp_par[4], &temp_par[5]);
 
 1245                         long NuclearChargeM1 = NuclearCharge-1;
 
 1247                         if(M_state == 1 && NuclearChargeM1<LIMELM)
 
 1249                                 ASSERT( NuclearChargeM1 < LIMELM );
 
 1250                                 ASSERT( NumberElectrons <= LIMELM );
 
 1255                                         RRFitPar[NuclearChargeM1][NumberElectrons][i] = temp_par[i];
 
 1263         for( 
long nelem=0; nelem<
LIMELM; nelem++ )
 
 1265                 for( 
long ion=0; ion<nelem+1; ion++ )
 
 1269                                 fprintf(ofp, 
"%li %li %e %e %e %e %e %e\n",
 
 1270                                         nelem, ion, 
RRFitPar[nelem][ion][0], 
 
 1278         fprintf(ofp, 
"total lines are %i ", count);
 
 1286                 enum {DEBUG_LOC=
false};
 
 1292                                 for( 
int ion=0; ion<=nelem; ++ion )
 
 1298                                 for( 
int ion=0; ion<=nelem; ++ion )
 
 1324         for( 
long nelem=0; nelem<
LIMELM; ++nelem )
 
 1333         static double TeUsed = -1 , EdenUsed = -1.;
 
 1347                 for( 
long ion=0; ion < nelem+1; ++ion )
 
 1349                         long int n_bnd_elec_before_recom ,
 
 1350                                 n_bnd_elec_after_recom;
 
 1352                         n_bnd_elec_before_recom = nelem-ion;
 
 1353                         n_bnd_elec_after_recom = nelem-ion+1;
 
 1368                                 n_bnd_elec_before_recom )) >= 0. )
 
 1385                                 n_bnd_elec_after_recom ,
 
 1393                                 n_bnd_elec_before_recom )) >= 0. )
 
 1409         static const double Fe_Gu_c[9][6] = {
 
 1410                 { 2.50507e-11, 5.60226e-11, 1.85001e-10, 3.57495e-9, 1.66321e-7, 0. },
 
 1411                 { 9.19610e-11, 2.92460e-10, 1.02120e-9, 1.14852e-8, 3.25418e-7, 0. }, 
 
 1412                 { 9.02625e-11, 6.22962e-10, 5.77545e-9, 1.78847e-8, 3.40610e-7, 0. }, 
 
 1413                 { 9.04286e-12, 9.68148e-10, 4.83636e-9, 2.48159e-8, 3.96815e-7, 0. }, 
 
 1414                 { 6.77873e-10, 1.47252e-9, 5.31202e-9, 2.54793e-8, 3.47407e-7, 0. }, 
 
 1415                 { 1.29742e-9, 4.10172e-9, 1.23605e-8, 2.33615e-8, 2.97261e-7, 0. }, 
 
 1416                 { 8.78027e-10, 2.31680e-9, 3.49333e-9, 1.16927e-8, 8.18537e-8, 1.54740e-7 },
 
 1417                 { 2.23178e-10, 1.87313e-9, 2.86171e-9, 1.38575e-8, 1.17803e-7, 1.06251e-7 },
 
 1418                 { 2.17263e-10, 7.35929e-10, 2.81276e-9, 1.32411e-8, 1.15761e-7, 4.80389e-8 }
 
 1421         static const double Fe_Gu_E[9][6] = {
 
 1422                 { 8.30501e-2, 8.52897e-1, 3.40225e0, 2.23053e1, 6.80367e1, 0. }, 
 
 1423                 { 1.44392e-1, 9.23999e-1, 5.45498e0, 2.04301e1, 7.06112e1, 0. },  
 
 1424                 { 5.79132e-2, 1.27852e0, 3.22439e0, 1.79602e1, 6.96277e1, 0. }, 
 
 1425                 { 1.02421e-1, 1.79393e0, 4.83226e0, 1.91117e1, 6.80858e1, 0. }, 
 
 1426                 { 1.24630e-1, 6.86045e-1, 3.09611e0, 1.44023e1, 6.42820e1, 0. }, 
 
 1427                 { 1.34459e-1, 6.63028e-1, 2.61753e0, 1.30392e1, 6.10222e1, 0. }, 
 
 1428                 { 7.79748e-2, 5.35522e-1, 1.88407e0, 8.38459e0, 3.38613e1, 7.89706e1 }, 
 
 1429                 { 8.83019e-2, 6.12756e-1, 2.36035e0, 9.61736e0, 3.64467e1, 8.72406e1 }, 
 
 1430                 { 1.51322e-1, 5.63155e-1, 2.57013e0, 9.08166e0, 3.69528e1, 1.08067e2 } 
 
 1440         for( 
long ion=0; ion<9; ion++ )
 
 1446                         for( 
long i=0; i<6; i++ )
 
 1458         static const double BadnelDR_RateSave[
LIMELM] =
 
 1460                         3.78e-13, 1.70e-12, 8.14e-12, 1.60e-11, 2.38e-11,
 
 1461                         6.42e-11, 5.97e-11, 1.47e-10, 1.11e-10, 3.26e-10,
 
 1462                         1.88e-10, 2.06e-10, 4.14e-10, 3.97e-10, 2.07e-10,
 
 1463                         2.46e-10, 3.38e-10, 3.15e-10, 9.70e-11, 6.49e-11,
 
 1464                         6.93e-10, 3.70e-10, 3.29e-11, 4.96e-11, 5.03e-11,
 
 1465                         2.91e-12, 4.62e-14, 0.00e+00, 0.00e+00, 0.00e+00
 
 1467         for( 
long nelem=0; nelem < 
LIMELM; ++nelem )
 
 1470                         BadnelDR_RateSave[nelem] * 
RecNoise[nelem] *
 
 1477         for( 
long ion=0; ion < 
ipIRON+1; ++ion )
 
 1488         for( 
long nelem=0; nelem < 
LIMELM; ++nelem )
 
 1490                 for( 
long ion=0; ion < nelem+1; ++ion )
 
 1505                         for( 
long ion=0; ion < nelem; ++ion )
 
 1531         static bool lgRunOnce = 
true;
 
 1538                         FILE *ioREC = 
ioQQQ;
 
 1541                         fprintf(ioREC, 
"\n\n##################################################\n");
 
 1542                         fprintf(ioREC,
"radiative recombination data sources \n" );
 
 1544                         for( 
long loop=0;loop<30;loop+=10)
 
 1547                                 for(
long  ion=loop; ion<loop+10; ++ion )
 
 1552                                 for( 
long nelem=loop; nelem<
LIMELM; ++nelem )
 
 1555                                         long limit = 
MIN2(nelem+1,loop+10);
 
 1556                                         for( 
long ion=loop; ion<limit; ++ion )
 
 1560                                         for( 
long ion=limit; ion<loop+10; ++ion )
 
 1567                         fprintf(ioREC,
"\nRadiative recombination data sources\n");
 
 1568                         fprintf(ioREC,
"Bad06: Badnell, N., 2006, ApJ, 167, 334B\n");
 
 1569                         fprintf(ioREC,
"Verner: Verner & Ferland, 1996, ApJS, 103, 467\n");
 
 1571                         fprintf(ioREC, 
"\n\n##################################################\n");
 
 1572                         fprintf(ioREC,
"Dielectronic recombination data sources \n" );
 
 1574                         for( 
long loop=0;loop<30;loop+=10)
 
 1577                                 for(
long  ion=loop; ion<loop+10; ++ion )
 
 1582                                 for( 
long nelem=loop; nelem<
LIMELM; ++nelem )
 
 1586                                         long limit = 
MIN2(nelem+1,loop+10);
 
 1587                                         for( 
long ion=loop; ion<limit; ++ion )
 
 1591                                         for( 
long ion=limit; ion<loop+10; ++ion )
 
 1598                         fprintf(ioREC,
"\nDielectronic data sources\nBadWeb: Badnell web site http://amdpp.phys.strath.ac.uk/tamoc/DR/\n");
 
 1599                         fprintf(ioREC,
"Bad06D: Badnell, N., 2006, ApJ, 651, L73\n");
 
 1600                         fprintf(ioREC,
"GuPC: Gu, M. private communication\n");
 
 1601                         fprintf(ioREC,
"mean: DR recombination ion mean (see below)\n");
 
 1602                         fprintf(ioREC,
"mean+: DR recombination ion mean (see below) + Arnaud & Raymond 1992, ApJ, 398, 394 \n");
 
 1612                                         for( 
long ion=0; ion<nelem+1; ++ion )
 
 1617                                         for( 
long ion=0; ion<nelem+1; ++ion )
 
 1632                                 fprintf( 
ioQQQ, 
"\n\nCollisSuppres finds following dielectronic" 
 1633                                         " recom suppression factors, Te=%10.3e eden=%10.3e\n",
 
 1638                                         for( 
long ion=0; ion < nelem; ++ion )
 
double ** DR_Badnell_rate_coef
double ** RR_Badnell_rate_coef
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
STATIC double Badnell_DR_rate_eval(int nAtomicNumberCScale, int n_core_e_before_recomb)
double DielecRecombVsTemp[NUM_DR_TEMPS]
NORETURN void TotalInsanity(void)
double ** RR_Verner_rate_coef
static double DR_Badnell_rate_coef_mean_ion[LIMELM]
long nMatch(const char *chKey, const char *chCard)
static bool ** lgDRBadnellDefinedPart2
static const int MAX_FIT_PAR_DR
static bool ** lgDRBadnellDefined
sys_float sexp(sys_float x)
bool lgRecom_Badnell_print
t_elementnames elementnames
t_iso_sp iso_sp[NISO][LIMELM]
static double RecNoise[LIMELM]
STATIC double CollisSuppres(long int atomic_number, long int ionic_charge, double eden, double T)
bool fp_equal(sys_float x, sys_float y, int n=3)
void Badnell_rec_init(void)
long int n_HighestResolved_max
static char chRRDataSource[LIMELM][LIMELM][10]
static double *** DRFitParPart1
double atmdat_dielrec_fe(long int ion, double t)
static char chDRDataSource[LIMELM][LIMELM][10]
double DR_mean_scale[LIMELM]
static bool lgMustMallocRec
const int INPUT_LINE_LENGTH
void ion_recom_calculate(void)
static double *** DRFitParPart2
double powi(double, long int)
const char * strchr_s(const char *s, int c)
static double *** RRFitPar
char chElementNameShort[LIMELM][CHARS_ELEMENT_NAME_SHORT]
double RandGauss(double xMean, double s)
multi_arr< long, 3 > QuantumNumbers2Index
static bool ** lgRRBadnellDefined
double rad_rec(long int iz, long int in, double t)
#define DEBUG_ENTRY(funcname)
double powpq(double x, int p, int q)
multi_arr< double, 2 > DR_Badnell_suppress_fact
int fprintf(const Output &stream, const char *format,...)
STATIC double Badnell_RR_rate_eval(int nAtomicNumberCScale, int n_core_e_before_recomb)
double pow(double x, int i)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
static bool ** lgDR_BadWeb_exist
double ** RR_rate_coef_used
static const int MAX_FIT_PAR_RR
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)