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-2017 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:84
bool nMatch(const char *chKey) const
Definition: parser.h:140
double FFmtRead(void)
Definition: parser.cpp:438
double exp10(double x)
Definition: cddefines.h:1383
t_input input
Definition: input.cpp:12
long int nvfpnt[LIMPAR]
Definition: optimize.h:198
long int m_nqh
Definition: parser.h:52
double totpow[LIMSPC]
Definition: rfield.h:286
char chRSpec[LIMSPC][5]
Definition: rfield.h:333
long int nRead
Definition: input.h:62
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:42
bool lgVarOn
Definition: optimize.h:207
bool lgTimeVary[LIMSPC]
Definition: rfield.h:292
double range[LIMSPC][2]
Definition: rfield.h:329
const int LIMSPC
Definition: rfield.h:20
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:484
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:318
t_optimize optimize
Definition: optimize.cpp:6
char chSpNorm[LIMSPC][5]
Definition: rfield.h:333
realnum vincr[LIMPAR]
Definition: optimize.h:195
bool lgOptimizeAsLinear[LIMPAR]
Definition: optimize.h:184
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:729
double egamry() const
Definition: mesh.h:88
bool lgEOL(void) const
Definition: parser.h:103
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1217
double pow(double x, int i)
Definition: cddefines.h:782
long int nvarxt[LIMPAR]
Definition: optimize.h:198