cloudy trunk
Loading...
Searching...
No Matches
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 )
106 radius.StopThickness[0] = a - radius.Radius;
107 else
108 radius.StopThickness[0] = a;
109
110 for( long int i=1; i < iterations.iter_malloc; i++ )
111 {
112 radius.StopThickness[i] = radius.StopThickness[0];
113 }
114 }
115
116 /* vary option */
117 if( optimize.lgVarOn )
118 {
119 /* pointer to where to write */
120 optimize.nvfpnt[optimize.nparm] = input.nRead;
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" );
126 optimize.nvarxt[optimize.nparm] = 2;
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" );
141 optimize.nvarxt[optimize.nparm] = 1;
142 }
143
144 /* log of radius is first number */
145 optimize.vparm[0][optimize.nparm] = (realnum)log10(radius.Radius);
146 optimize.vincr[optimize.nparm] = 0.5;
147 ++optimize.nparm;
148 }
149 return;
150}
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
t_input input
Definition input.cpp:12
t_iterations iterations
Definition iterations.cpp:5
t_optimize optimize
Definition optimize.cpp:5
void ParseRadius(Parser &p)
UNUSED const double PARSEC
Definition physconst.h:138
t_radius radius
Definition radius.cpp:5