cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse_ratio.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 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 
11 {
12  bool lgAoxOn;
13  double aox;
14 
15  DEBUG_ENTRY( "ParseRatio()" );
16 
17  /* enter a continuum luminosity as a ratio of
18  * nuFnu for this continuum relative to a previous continuum
19  * format; first number is ratio of second to first continuum
20  * second number is energy for this ratio
21  * if third numbewr on line, then 2nd number is energy of
22  * first continuum, while 3rd number is energy of second continuum */
23 
24  if( p.m_nqh == 0 )
25  {
26  fprintf( ioQQQ, " Can\'t form ratio since this is first continuum.\n" );
28  }
29 
30  /* per sq cm or luminosity is really irrelevant */
31  strcpy( rfield.chRSpec[p.m_nqh], "SQCM" );
32  strcpy( rfield.chSpNorm[p.m_nqh], "RATI" );
33 
34  /* this option is to specify alpha ox */
35  if( p.nMatch("ALPH") )
36  {
37  /* lgAoxOn is flag saying that we will spicify alpha ox */
38  lgAoxOn = true;
39  /* only one parameter to be recognized, alpha ox */
40  aox = p.FFmtRead();
41 
42  /* 403.3 is ratio of energies where alpha ox defined,
43  * assumed to be 2500A and 2keV */
44  rfield.totpow[p.m_nqh] = pow(403.3,aox);
45  rfield.range[p.m_nqh][0] = 0.3645;
46  rfield.range[p.m_nqh][1] = 147.;
47  }
48 
49  else
50  {
51  /* set flag saying that alpha ox will not be specified */
52  lgAoxOn = false;
53  /* set this to impossible number since not used, but lint needs a value */
54  aox = -DBL_MAX;
55  /* specify ratio, two energies */
56  rfield.totpow[p.m_nqh] = p.FFmtRead();
57  if( p.lgEOL() )
58  p.NoNumb("continuum ratio");
59 
60  /* assumed to be a log if negative or zero */
61  if( rfield.totpow[p.m_nqh] <= 0. || p.nMatch(" LOG" ) )
62  {
64  }
65 
66  rfield.range[p.m_nqh][0] = p.FFmtRead();
67  if( p.lgEOL() )
68  {
69  fprintf( ioQQQ, " There must be at least 2 numbers on this line.\n" );
70  fprintf( ioQQQ, " The ratio, and one or two energies\n" );
72  }
73 
74  rfield.range[p.m_nqh][1] = p.FFmtRead();
75  /* if only one number then assume same for each */
76  if( p.lgEOL() )
77  rfield.range[p.m_nqh][1] = rfield.range[p.m_nqh][0];
78 
79  if( rfield.range[p.m_nqh][0] < rfield.emm() ||
80  rfield.range[p.m_nqh][1] < rfield.emm() )
81  {
82  fprintf( ioQQQ, " One of the energies is too low, outside the range of the code.\n" );
84  }
85  if( rfield.range[p.m_nqh][0] > rfield.egamry() ||
86  rfield.range[p.m_nqh][1] > rfield.egamry() )
87  {
88  fprintf( ioQQQ, " One of the energies is too high, outside the range of the code.\n" );
90  }
91  }
92 
93  /* >>chng 06 mar 22, add time option to vary only some continua with time */
94  if( p.nMatch( "TIME" ) )
95  rfield.lgTimeVary[p.m_nqh] = true;
96 
97  /* vary option */
98  if( optimize.lgVarOn )
99  {
100  /* pointer to where to write */
102  if( lgAoxOn )
103  {
104  /* this is the number of parameters to feed onto the input line */
106  /* vary alpha ox */
107  strcpy( optimize.chVarFmt[optimize.nparm], "RATIO alphox %f" );
109  /* param is linear scale factor */
110  optimize.vparm[0][optimize.nparm] = (realnum)aox;
111  optimize.vincr[optimize.nparm] = 0.2f;
112  }
113  else
114  {
115  /* this is the number of parameters to feed onto the input line */
117  strcpy( optimize.chVarFmt[optimize.nparm], "RATIO LOG %f %f %f" );
118  /* param is log of abundance by number relative to hydrogen */
122  optimize.vincr[optimize.nparm] = 0.2f;
123  }
124  if( rfield.lgTimeVary[p.m_nqh] )
125  strcat( optimize.chVarFmt[optimize.nparm], " TIME" );
126  ++optimize.nparm;
127  }
128 
129  ++p.m_nqh;
130  if( p.m_nqh >= LIMSPC )
131  {
132  fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" );
134  }
135 
136  return;
137 }
double emm() const
Definition: mesh.h:93
bool nMatch(const char *chKey) const
Definition: parser.h:150
double FFmtRead(void)
Definition: parser.cpp:472
double exp10(double x)
Definition: cddefines.h:1368
t_input input
Definition: input.cpp:12
long int nvfpnt[LIMPAR]
Definition: optimize.h:198
long int m_nqh
Definition: parser.h:54
double totpow[LIMSPC]
Definition: rfield.h:284
char chRSpec[LIMSPC][5]
Definition: rfield.h:335
long int nRead
Definition: input.h:105
void ParseRatio(Parser &p)
Definition: parse_ratio.cpp:10
char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2]
Definition: optimize.h:267
FILE * ioQQQ
Definition: cddefines.cpp:7
realnum vparm[LIMEXT][LIMPAR]
Definition: optimize.h:192
Definition: parser.h:43
bool lgVarOn
Definition: optimize.h:207
bool lgTimeVary[LIMSPC]
Definition: rfield.h:290
double range[LIMSPC][2]
Definition: rfield.h:331
const int LIMSPC
Definition: rfield.h:21
long int nparm
Definition: optimize.h:204
t_rfield rfield
Definition: rfield.cpp:9
float realnum
Definition: cddefines.h:124
#define EXIT_FAILURE
Definition: cddefines.h:168
#define cdEXIT(FAIL)
Definition: cddefines.h:482
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:345
t_optimize optimize
Definition: optimize.cpp:6
char chSpNorm[LIMSPC][5]
Definition: rfield.h:335
realnum vincr[LIMPAR]
Definition: optimize.h:195
bool lgOptimizeAsLinear[LIMPAR]
Definition: optimize.h:184
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
double egamry() const
Definition: mesh.h:97
bool lgEOL(void) const
Definition: parser.h:113
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
long int nvarxt[LIMPAR]
Definition: optimize.h:198