cloudy trunk
Loading...
Searching...
No Matches
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 */
105 optimize.nvfpnt[optimize.nparm] = input.nRead;
106 if( lgAoxOn )
107 {
108 /* this is the number of parameters to feed onto the input line */
109 optimize.nvarxt[optimize.nparm] = 1;
110 /* vary alpha ox */
111 strcpy( optimize.chVarFmt[optimize.nparm], "RATIO alphox %f" );
112 optimize.lgOptimizeAsLinear[optimize.nparm] = true;
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 */
120 optimize.nvarxt[optimize.nparm] = 3;
121 strcpy( optimize.chVarFmt[optimize.nparm], "RATIO LOG %f %f %f" );
122 /* param is log of abundance by number relative to hydrogen */
123 optimize.vparm[0][optimize.nparm] = (realnum)log10(rfield.totpow[p.m_nqh]);
124 optimize.vparm[1][optimize.nparm] = (realnum)rfield.range[p.m_nqh][0];
125 optimize.vparm[2][optimize.nparm] = (realnum)rfield.range[p.m_nqh][1];
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
FILE * ioQQQ
Definition cddefines.cpp:7
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
float realnum
Definition cddefines.h:103
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
double FFmtRead(void)
Definition parser.cpp:353
bool nMatch(const char *chKey) const
Definition parser.h:135
bool lgEOL(void) const
Definition parser.h:98
NORETURN void NoNumb(const char *chDesc) const
Definition parser.cpp:233
long int m_nqh
Definition parser.h:41
t_input input
Definition input.cpp:12
t_optimize optimize
Definition optimize.cpp:5
void ParseRatio(Parser &p)
t_rfield rfield
Definition rfield.cpp:8
const int LIMSPC
Definition rfield.h:18