cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse_radius.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 /*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 = exp10(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 = exp10(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  iterations.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 }
bool nMatch(const char *chKey) const
Definition: parser.h:140
long int iter_malloc
Definition: iterations.h:40
double Radius
Definition: radius.h:31
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 nRead
Definition: input.h:62
char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2]
Definition: optimize.h:267
vector< double > StopThickness
Definition: iterations.h:77
FILE * ioQQQ
Definition: cddefines.cpp:7
realnum vparm[LIMEXT][LIMPAR]
Definition: optimize.h:192
Definition: parser.h:42
bool lgVarOn
Definition: optimize.h:207
long int nparm
Definition: optimize.h:204
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
bool lgRadiusKnown
Definition: radius.h:121
t_iterations iterations
Definition: iterations.cpp:6
t_optimize optimize
Definition: optimize.cpp:6
t_radius radius
Definition: radius.cpp:5
realnum vincr[LIMPAR]
Definition: optimize.h:195
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:729
void ParseRadius(Parser &p)
bool lgEOL(void) const
Definition: parser.h:103
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1217
long int nvarxt[LIMPAR]
Definition: optimize.h:198