cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse_powerlawcontinuum.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 /*ParsePowerlawContinuum parse the power law continuum command */
4 #include "cddefines.h"
5 #include "rfield.h"
6 #include "optimize.h"
7 #include "input.h"
8 #include "parser.h"
9 
11 {
12  DEBUG_ENTRY( "ParsePowerlawContinuum()" );
13 
14  /* power law with cutoff and X-ray continuum */
15  strcpy( rfield.chSpType[rfield.nShape], "POWER" );
16 
17  /* first parameter is slope of continuum, probably should be negative */
19  if( p.lgEOL() )
20  {
21  fprintf( ioQQQ, " There should have been a number on this line. Sorry.\n" );
23  }
24 
25  if( rfield.slope[rfield.nShape] >= 0. )
26  {
27  fprintf( ioQQQ, " Is the slope of this power law correct?\n" );
28  }
29 
30  /* second optional parameter is high energy cut off */
32 
33  /* no cutoff if eof hit */
34  if( p.lgEOL() )
35  {
36  /* no extra parameters at all, so put in extreme cutoffs */
37  rfield.cutoff[rfield.nShape][0] = 1e4;
38  rfield.cutoff[rfield.nShape][1] = 1e-4;
39  }
40  else
41  {
42  /* first cutoff was present, check for second */
44  if( p.lgEOL() )
45  rfield.cutoff[rfield.nShape][1] = 1e-4;
46  }
47 
48  /* check that energies were entered in the correct order */
50  {
51  fprintf( ioQQQ, " The optional cutoff energies do not appear to be in the correct order. Check Hazy.\n" );
53  }
54 
55  /* check for keyword KELVIN to interpret cutoff energies as degrees */
56  if( p.nMatch("KELV") )
57  {
58  /* temps are log if first le 10 */
59  if( rfield.cutoff[rfield.nShape][0] <= 10. || p.nMatch(" LOG") )
61  if( rfield.cutoff[rfield.nShape][1] <= 10. || p.nMatch(" LOG") )
63  rfield.cutoff[rfield.nShape][0] /= TE1RYD;
64  rfield.cutoff[rfield.nShape][1] /= TE1RYD;
65  }
66 
67  if( rfield.cutoff[rfield.nShape][0] < 0. ||
68  rfield.cutoff[rfield.nShape][1] < 0. )
69  {
70  fprintf( ioQQQ, " A negative cutoff energy is not physical. Sorry.\n" );
72  }
73 
74  if( rfield.cutoff[rfield.nShape][1] == 0. &&
75  rfield.slope[rfield.nShape] <= -1. )
76  {
77  fprintf( ioQQQ, " A power-law with this slope, and no low energy cutoff, may have an unphysically large\n brightness temperature in the radio.\n" );
78  }
79 
80  /* vary option */
81  if( optimize.lgVarOn )
82  {
83  /* pointer to where to write */
85  if( p.nMatch("VARYB") )
86  {
87  /* this test is for key "varyb", meaning to vary second parameter
88  * the cutoff temperature
89  * this is the number of parameters to feed onto the input line */
91  sprintf( optimize.chVarFmt[optimize.nparm], "POWER LAW %f KELVIN %%f %f LOG",
93  log10(rfield.cutoff[rfield.nShape][1]*TE1RYD) );
95  (realnum)log10(rfield.cutoff[rfield.nShape][0]*TE1RYD);
96  optimize.varang[optimize.nparm][0] = (realnum)log10(rfield.cutoff[rfield.nShape][1]*TE1RYD);
97  optimize.varang[optimize.nparm][1] = FLT_MAX;
98  optimize.vincr[optimize.nparm] = 0.2f;
99  }
100  else if( p.nMatch("VARYC") )
101  {
102  /* the keyword was "varyc"
103  * this is the number of parameters to feed onto the input line */
105  sprintf( optimize.chVarFmt[optimize.nparm], "POWER LAW %f KELVIN %f %%f LOG",
107  log10(rfield.cutoff[rfield.nShape][0]*TE1RYD) );
109  (realnum)log10(rfield.cutoff[rfield.nShape][1]*TE1RYD);
110  optimize.varang[optimize.nparm][0] = -FLT_MAX;
111  optimize.varang[optimize.nparm][1] = (realnum)log10(rfield.cutoff[rfield.nShape][0]*TE1RYD);
112  optimize.vincr[optimize.nparm] = 0.2f;
113  }
114  else
115  {
116  /* vary the first parameter only, but still are two more
117  * this is the number of parameters to feed onto the input line */
119  sprintf( optimize.chVarFmt[optimize.nparm], "POWER LAW %%f KELVIN %f %f LOG",
120  log10(rfield.cutoff[rfield.nShape][0]*TE1RYD),
121  log10(rfield.cutoff[rfield.nShape][1]*TE1RYD) );
123  optimize.vincr[optimize.nparm] = 0.2f;
124  }
125  ++optimize.nparm;
126  }
127 
128  /*>>chng 06 nov 10, BUGFIX, nShape was incremented before previous branch
129  * and so crashed with log10 0 since nSpage was beyond set values
130  * caused fpe domain function error with log 0
131  * fpe caught by Pavel Abolmasov */
132  ++rfield.nShape;
133  if( rfield.nShape >= LIMSPC )
134  {
135  fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" );
137  }
138 
139  return;
140 }
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
realnum varang[LIMPAR][2]
Definition: optimize.h:201
long int nRead
Definition: input.h:105
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
double cutoff[LIMSPC][3]
Definition: rfield.h:284
bool lgVarOn
Definition: optimize.h:207
const int LIMSPC
Definition: rfield.h:21
double slope[LIMSPC]
Definition: rfield.h:284
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
t_optimize optimize
Definition: optimize.cpp:6
realnum vincr[LIMPAR]
Definition: optimize.h:195
void ParsePowerlawContinuum(Parser &p)
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
bool lgEOL(void) const
Definition: parser.h:113
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
long int nShape
Definition: rfield.h:306
long int nvarxt[LIMPAR]
Definition: optimize.h:198
char chSpType[LIMSPC][6]
Definition: rfield.h:335