cloudy  trunk
 All Data Structures 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-2008 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 "parse.h"
12 
13 void ParseRadius(char *chCard,
14  realnum *ar1)
15 {
16  bool lgEOL,
17  lgR2set,
18  lgRLog;
19  long int i;
20  double a,
21  convl;
22 
23  DEBUG_ENTRY( "ParseRadius()" );
24 
25  /* log of inner and outer radii, default second=infinity,
26  * if R2<R1 then R2=R1+R2
27  * there is an optional keyword, "PARSEC" on the line, to use PC as units */
28  if( nMatch("PARS",chCard) )
29  {
30  /*>>chng 06 mar 18, from above to below */
31  /*convl = PARSCL;*/
32  convl = log10( PARSEC );
33  }
34  else
35  {
36  convl = 0.;
37  }
38 
39  /* if linear appears on line, then radius is linear, otherwise, log */
40  if( nMatch("LINE",chCard) )
41  {
42  lgRLog = false;
43  }
44  else
45  {
46  lgRLog = true;
47  }
48 
49  i = 5;
50  *ar1 = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
51  if( lgEOL )
52  {
53  fprintf( ioQQQ, " There should have been a number on this line. Sorry.\n" );
54  cdEXIT(EXIT_FAILURE);
55  }
56 
57  /* option for linear or log radius */
58  if( lgRLog )
59  {
60  *ar1 += (realnum)convl;
61  }
62  else
63  {
64  if( *ar1 > 0. )
65  {
66  *ar1 = (realnum)(log10(*ar1) + convl);
67  }
68  else
69  {
70  fprintf(ioQQQ,"The first radius is negative and linear radius is set - this is impossible.\n");
71  cdEXIT(EXIT_FAILURE);
72  }
73  }
74 
75  if( *ar1 > 37 || *ar1 < -37. )
76  {
77  fprintf(ioQQQ,"WARNING - the log of the radius is %e - this is too big and I would crash.\n", *ar1 );
78  fprintf(ioQQQ," Sorry.\n" );
79  cdEXIT(EXIT_FAILURE);
80  }
81 
82  radius.Radius = pow((realnum)10.f ,*ar1);
83  radius.lgRadiusKnown = true;
84 
85  /* check for second number, which indicates thickness or outer radius of model */
86  a = (double)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
87  if( lgEOL )
88  {
89  /* not set */
90  lgR2set = false;
91  }
92  else
93  {
94  /* outer radius is set, */
95  lgR2set = true;
96 
97  /* log or linear option is still in place */
98  if( lgRLog )
99  {
100  a += convl;
101  }
102 
103  else
104  {
105  /* linear radius - convert to log but first make sure that a is > 0 */
106  if( a > 0. )
107  {
108  a = log10(a) + convl;
109  }
110  else
111  {
112  fprintf(ioQQQ,"The second radius is negative and linear radius is set - this is impossible.\n");
113  cdEXIT(EXIT_FAILURE);
114  }
115  }
116 
117  if( a > 37 || a < -37. )
118  {
119  fprintf(ioQQQ,"WARNING - the log of the outer radius is %e - this is too big and I will soon crash.\n", a );
120  /* flush buffers since we shall soon throw an fpe */
121  fflush( ioQQQ );
122  }
123  a = pow(10.,a);
124  /* check whether it was thickness or outer radius,
125  * we want router to be total thickness of modeled region,
126  * NOT outer radius */
127  if( a > radius.Radius )
128  {
129  radius.router[0] = a - radius.Radius;
130  }
131 
132  else
133  {
134  radius.router[0] = a;
135  }
136 
137  for( i=1; i < iterations.iter_malloc; i++ )
138  {
139  radius.router[i] = radius.router[0];
140  }
141  }
142 
143  /* vary option */
144  if( optimize.lgVarOn )
145  {
146  /* pointer to where to write */
148  optimize.vincr[optimize.nparm] = 0.5;
149 
150  /* flag saying second outer radius or thickness was set */
151  if( lgR2set )
152  {
153  strcpy( optimize.chVarFmt[optimize.nparm], "RADIUS %f depth or outer R %f" );
155  /* second number is thickness or outer radius */
156  optimize.vparm[1][optimize.nparm] = (realnum)log10(radius.router[0]);
157  fprintf(ioQQQ,
158  " WARNING - outer radius or thickness was set with a variable radius.\n");
159  fprintf(ioQQQ,
160  " The interpretation of the second number can change from radius to depth as radius changes.\n");
161  fprintf(ioQQQ,
162  " Do not use the second parameter unless you are quite certain that you know what you are doing.\n");
163  fprintf(ioQQQ,
164  " Consider using the STOP THICKNESS command instead.\n");
165  }
166  else
167  {
168  strcpy( optimize.chVarFmt[optimize.nparm], "RADIUS= %f" );
170  }
171 
172  /* log of radius is first number */
174  ++optimize.nparm;
175  }
176  return;
177 }

Generated for cloudy by doxygen 1.8.4