cloudy  trunk
parse_radius.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 /*ParseRadius parse the radius command */
4 #include "cddefines.h"
5 /*#define PARSCL 18.489396*/
6 #include "physconst.h"
7 #include "optimize.h"
8 #include "radius.h"
9 #include "iterations.h"
10 #include "input.h"
11 #include "parser.h"
12 
14 {
15  bool
16  lgR2set,
17  lgRLog;
18  double a,
19  convl,
20  r;
21 
22  DEBUG_ENTRY( "ParseRadius()" );
23 
24  /* log of inner and outer radii, default second=infinity,
25  * if R2<R1 then R2=R1+R2
26  * there is an optional keyword, "PARSEC" on the line, to use PC as units */
27  convl = p.nMatch("PARS") ? log10( PARSEC ) : 0.;
28 
29  /* if linear appears on line, then radius is linear, otherwise, log */
30  lgRLog = !p.nMatch("LINE");
31 
32  r = p.FFmtRead();
33  if( p.lgEOL() )
34  p.NoNumb("radius");
35 
36  /* option for linear or log radius */
37  if( lgRLog )
38  {
39  r += convl;
40  }
41  else
42  {
43  if( r > 0. )
44  {
45  r = log10(r) + convl;
46  }
47  else
48  {
49  fprintf(ioQQQ,"The first radius is negative and linear is set - this is impossible.\n");
51  }
52  }
53 
54  if( r > 37. || r < -37. )
55  {
56  fprintf(ioQQQ,"WARNING - the log of the radius is %e - this is too big.\n", r );
57  fprintf(ioQQQ," Sorry.\n" );
59  }
60 
61  radius.Radius = pow(10.,r);
62  radius.lgRadiusKnown = true;
63 
64  /* check for second number, which indicates thickness or outer radius of model */
65  a = p.FFmtRead();
66  if( p.lgEOL() )
67  {
68  /* not set */
69  lgR2set = false;
70  }
71  else
72  {
73  /* outer radius is set, */
74  lgR2set = true;
75 
76  /* log or linear option is still in place */
77  if( lgRLog )
78  {
79  a += convl;
80  }
81  else
82  {
83  /* linear radius - convert to log but first make sure that a is > 0 */
84  if( a > 0. )
85  {
86  a = log10(a) + convl;
87  }
88  else
89  {
90  fprintf(ioQQQ,"The second radius is negative and linear is set - this is impossible.\n");
92  }
93  }
94 
95  if( a > 37. || a < -37. )
96  {
97  fprintf(ioQQQ,"WARNING - the log of the second radius is %e - this is too big.\n", a );
98  /* flush buffers since we shall soon throw an fpe */
99  fflush( ioQQQ );
100  }
101  a = pow(10.,a);
102  /* check whether it was thickness or outer radius,
103  * we want thickness to be total thickness of modeled region,
104  * NOT outer radius */
105  if( a > radius.Radius )
107  else
108  radius.StopThickness[0] = a;
109 
110  for( long int i=1; i < iterations.iter_malloc; i++ )
111  {
113  }
114  }
115 
116  /* vary option */
117  if( optimize.lgVarOn )
118  {
119  /* pointer to where to write */
121 
122  /* flag saying second outer radius or thickness was set */
123  if( lgR2set )
124  {
125  strcpy( optimize.chVarFmt[optimize.nparm], "RADIUS %f depth or outer R %f LOG" );
127  /* second number is thickness or outer radius */
128  optimize.vparm[1][optimize.nparm] = (realnum)log10(a);
129  fprintf(ioQQQ,
130  " WARNING - outer radius or thickness was set with a variable radius.\n");
131  fprintf(ioQQQ,
132  " The interpretation of the second number can change from radius to depth as radius changes.\n");
133  fprintf(ioQQQ,
134  " Do not use the second parameter unless you are certain that you know what you are doing.\n");
135  fprintf(ioQQQ,
136  " Consider using the STOP THICKNESS or STOP RADIUS command instead.\n");
137  }
138  else
139  {
140  strcpy( optimize.chVarFmt[optimize.nparm], "RADIUS= %f LOG" );
142  }
143 
144  /* log of radius is first number */
146  optimize.vincr[optimize.nparm] = 0.5;
147  ++optimize.nparm;
148  }
149  return;
150 }
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
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
realnum
float realnum
Definition: cddefines.h:103
iterations
t_iterations iterations
Definition: iterations.cpp:5
t_optimize::lgVarOn
bool lgVarOn
Definition: optimize.h:203
input
t_input input
Definition: input.cpp:12
t_radius::lgRadiusKnown
bool lgRadiusKnown
Definition: radius.h:116
radius
t_radius radius
Definition: radius.cpp:5
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
Parser::NoNumb
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:233
PARSEC
const UNUSED double PARSEC
Definition: physconst.h:138
Parser
Definition: parser.h:31
cddefines.h
t_radius::Radius
double Radius
Definition: radius.h:25
optimize.h
t_optimize::nvarxt
long int nvarxt[LIMPAR]
Definition: optimize.h:194
radius.h
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
Parser::lgEOL
bool lgEOL(void) const
Definition: parser.h:98
parser.h
t_radius::StopThickness
double * StopThickness
Definition: radius.h:55
physconst.h
t_optimize::nvfpnt
long int nvfpnt[LIMPAR]
Definition: optimize.h:195
ParseRadius
void ParseRadius(Parser &p)
Definition: parse_radius.cpp:13
iterations.h
t_iterations::iter_malloc
long int iter_malloc
Definition: iterations.h:29
input.h
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684