cloudy  trunk
parse_ratio.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*ParseRatio derive continuum luminosity of this continuum relative to previous */
4 #include "cddefines.h"
5 #include "optimize.h"
6 #include "input.h"
7 #include "rfield.h"
8 #include "parser.h"
9 /* HP cc cannot compile following except in -O1 mode */
10 #if defined(__HP_aCC)
11 #pragma OPT_LEVEL 1
12 #endif
13 
15 {
16  bool lgAoxOn;
17  double aox;
18 
19  DEBUG_ENTRY( "ParseRatio()" );
20 
21  /* enter a continuum luminosity as a ratio of
22  * nuFnu for this continuum relative to a previous continuum
23  * format; first number is ratio of second to first continuum
24  * second number is energy for this ratio
25  * if third numbewr on line, then 2nd number is energy of
26  * first continuum, while 3rd number is energy of second continuum */
27 
28  if( p.m_nqh == 0 )
29  {
30  fprintf( ioQQQ, " Can\'t form ratio since this is first continuum.\n" );
32  }
33 
34  /* per sq cm or luminosity is really irrelevant */
35  strcpy( rfield.chRSpec[p.m_nqh], "SQCM" );
36  strcpy( rfield.chSpNorm[p.m_nqh], "RATI" );
37 
38  /* this option is to specify alpha ox */
39  if( p.nMatch("ALPH") )
40  {
41  /* lgAoxOn is flag saying that we will spicify alpha ox */
42  lgAoxOn = true;
43  /* only one parameter to be recognized, alpha ox */
44  aox = p.FFmtRead();
45 
46  /* 403.3 is ratio of energies where alpha ox defined,
47  * assumed to be 2500A and 2keV */
48  rfield.totpow[p.m_nqh] = pow(403.3,aox);
49  rfield.range[p.m_nqh][0] = 0.3645;
50  rfield.range[p.m_nqh][1] = 147.;
51  }
52 
53  else
54  {
55  /* set flag saying that alpha ox will not be specified */
56  lgAoxOn = false;
57  /* set this to impossible number since not used, but lint needs a value */
58  aox = -DBL_MAX;
59  /* specify ratio, two energies */
60  rfield.totpow[p.m_nqh] = p.FFmtRead();
61  if( p.lgEOL() )
62  p.NoNumb("continuum ratio");
63 
64  /* assumed to be a log if negative or zero */
65  if( rfield.totpow[p.m_nqh] <= 0. || p.nMatch(" LOG" ) )
66  {
67  rfield.totpow[p.m_nqh] = pow(10.,rfield.totpow[p.m_nqh]);
68  }
69 
70  rfield.range[p.m_nqh][0] = p.FFmtRead();
71  if( p.lgEOL() )
72  {
73  fprintf( ioQQQ, " There must be at least 2 numbers on this line.\n" );
74  fprintf( ioQQQ, " The ratio, and one or two energies\n" );
76  }
77 
78  rfield.range[p.m_nqh][1] = p.FFmtRead();
79  /* if only one number then assume same for each */
80  if( p.lgEOL() )
81  rfield.range[p.m_nqh][1] = rfield.range[p.m_nqh][0];
82 
83  if( rfield.range[p.m_nqh][0] < rfield.emm ||
84  rfield.range[p.m_nqh][1] < rfield.emm )
85  {
86  fprintf( ioQQQ, " One of the energies is too low, outside the range of the code.\n" );
88  }
89  if( rfield.range[p.m_nqh][0] > rfield.egamry ||
90  rfield.range[p.m_nqh][1] > rfield.egamry )
91  {
92  fprintf( ioQQQ, " One of the energies is too high, outside the range of the code.\n" );
94  }
95  }
96 
97  /* >>chng 06 mar 22, add time option to vary only some continua with time */
98  if( p.nMatch( "TIME" ) )
99  rfield.lgTimeVary[p.m_nqh] = true;
100 
101  /* vary option */
102  if( optimize.lgVarOn )
103  {
104  /* pointer to where to write */
106  if( lgAoxOn )
107  {
108  /* this is the number of parameters to feed onto the input line */
110  /* vary alpha ox */
111  strcpy( optimize.chVarFmt[optimize.nparm], "RATIO alphox %f" );
113  /* param is linear scale factor */
114  optimize.vparm[0][optimize.nparm] = (realnum)aox;
115  optimize.vincr[optimize.nparm] = 0.2f;
116  }
117  else
118  {
119  /* this is the number of parameters to feed onto the input line */
121  strcpy( optimize.chVarFmt[optimize.nparm], "RATIO LOG %f %f %f" );
122  /* param is log of abundance by number relative to hydrogen */
126  optimize.vincr[optimize.nparm] = 0.2f;
127  }
128  if( rfield.lgTimeVary[p.m_nqh] )
129  strcat( optimize.chVarFmt[optimize.nparm], " TIME" );
130  ++optimize.nparm;
131  }
132 
133  ++p.m_nqh;
134  if( p.m_nqh >= LIMSPC )
135  {
136  fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" );
138  }
139 
140  return;
141 }
142 #if defined(__HP_aCC)
143 #pragma OPTIMIZE OFF
144 #pragma OPTIMIZE ON
145 #endif
t_rfield::totpow
double totpow[LIMSPC]
Definition: rfield.h:300
Parser::nMatch
bool nMatch(const char *chKey) const
Definition: parser.h:135
t_optimize::vincr
realnum vincr[LIMPAR]
Definition: optimize.h:191
Parser::FFmtRead
double FFmtRead(void)
Definition: parser.cpp:353
t_optimize::nparm
long int nparm
Definition: optimize.h:201
t_input::nRead
long int nRead
Definition: input.h:49
rfield
t_rfield rfield
Definition: rfield.cpp:8
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
realnum
float realnum
Definition: cddefines.h:103
rfield.h
t_optimize::lgVarOn
bool lgVarOn
Definition: optimize.h:203
LIMSPC
const int LIMSPC
Definition: rfield.h:18
input
t_input input
Definition: input.cpp:12
optimize
t_optimize optimize
Definition: optimize.cpp:5
t_optimize::vparm
realnum vparm[LIMEXT][LIMPAR]
Definition: optimize.h:188
t_optimize::chVarFmt
char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2]
Definition: optimize.h:263
EXIT_FAILURE
#define EXIT_FAILURE
Definition: cddefines.h:140
t_rfield::egamry
realnum egamry
Definition: rfield.h:52
t_rfield::chRSpec
char chRSpec[LIMSPC][5]
Definition: rfield.h:352
Parser::NoNumb
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:233
Parser
Definition: parser.h:31
cddefines.h
optimize.h
t_optimize::nvarxt
long int nvarxt[LIMPAR]
Definition: optimize.h:194
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
Parser::lgEOL
bool lgEOL(void) const
Definition: parser.h:98
t_rfield::lgTimeVary
bool lgTimeVary[LIMSPC]
Definition: rfield.h:306
t_rfield::range
double range[LIMSPC][2]
Definition: rfield.h:347
parser.h
t_optimize::lgOptimizeAsLinear
bool lgOptimizeAsLinear[LIMPAR]
Definition: optimize.h:180
t_optimize::nvfpnt
long int nvfpnt[LIMPAR]
Definition: optimize.h:195
Parser::m_nqh
long int m_nqh
Definition: parser.h:41
t_rfield::emm
realnum emm
Definition: rfield.h:49
t_rfield::chSpNorm
char chSpNorm[LIMSPC][5]
Definition: rfield.h:351
ParseRatio
void ParseRatio(Parser &p)
Definition: parse_ratio.cpp:14
input.h
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684