cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse_ratio.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 /*ParseRatio derive continuum luminosity of this continuum relative to previous */
4 #include "cddefines.h"
5 #include "optimize.h"
6 #include "input.h"
7 #include "rfield.h"
8 #include "parse.h"
9 /* HP cc cannot compile following except in -O1 mode */
10 #if defined(__HP_aCC)
11 #pragma OPT_LEVEL 1
12 #endif
13 
14 void ParseRatio(char *chCard,
15  long int *nqh)
16 {
17  bool lgAoxOn,
18  lgEOL;
19  long int i;
20  double aox;
21 
22  DEBUG_ENTRY( "ParseRatio()" );
23 
24  /* enter a continuum luminosity as a ratio of
25  * nuFnu for this continuum relative to a previous continuum
26  * format; first number is ratio of second to first continuum
27  * second number is energy for this ratio
28  * if third numbewr on line, then 2nd number is energy of
29  * first continuum, while 3rd number is energy of second continuum */
30 
31  if( *nqh == 0 )
32  {
33  fprintf( ioQQQ, " Can\'t form ratio since this is first continuum.\n" );
34  cdEXIT(EXIT_FAILURE);
35  }
36 
37  /* per sq cm or luminosity is really irrelevant */
38  strcpy( rfield.chRSpec[*nqh], "SQCM" );
39  strcpy( rfield.chSpNorm[*nqh], "RATI" );
40 
41  /* this option is to specify alpha ox */
42  if( nMatch("ALPH",chCard) )
43  {
44  /* lgAoxOn is flag saying that we will spicify alpha ox */
45  lgAoxOn = true;
46  /* only one parameter to be recognized, alpha ox */
47  i = 5;
48  aox = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
49 
50  /* 403.3 is ratio of energies where alpha ox defined,
51  * assumed to be 2500A and 2keV */
52  rfield.totpow[*nqh] = pow(403.3,aox);
53  rfield.range[*nqh][0] = 0.3645;
54  rfield.range[*nqh][1] = 147.;
55  }
56 
57  else
58  {
59  /* set flag saying that alpha ox will not be specified */
60  lgAoxOn = false;
61  /* set this to impossible number since not used, but lint needs a value */
62  aox = -DBL_MAX;
63  /* specify ratio, two energies */
64  i = 5;
65  rfield.totpow[*nqh] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
66 
67  /* assumed to be a log if negative or zero */
68  if( rfield.totpow[*nqh] <= 0. || nMatch(" LOG",chCard ) )
69  {
70  rfield.totpow[*nqh] = pow(10.,rfield.totpow[*nqh]);
71  }
72 
73  if( lgEOL )
74  {
75  fprintf( ioQQQ, " There must be a number on this line.\n" );
76  cdEXIT(EXIT_FAILURE);
77  }
78 
79  rfield.range[*nqh][0] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
80 
81  if( lgEOL )
82  {
83  fprintf( ioQQQ, " There must be at least 2 numbers on this line.\n" );
84  fprintf( ioQQQ, " The ratio, and two energies\n" );
85  cdEXIT(EXIT_FAILURE);
86  }
87 
88  rfield.range[*nqh][1] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
89 
90  /* if only one number then assume same for each */
91  if( lgEOL )
92  {
93  rfield.range[*nqh][1] = rfield.range[*nqh][0];
94  }
95 
96  if( rfield.range[*nqh][0] < rfield.emm ||
97  rfield.range[*nqh][1] < rfield.emm )
98  {
99  fprintf( ioQQQ, " One of the energies is too low, outside the range of the code.\n" );
100  cdEXIT(EXIT_FAILURE);
101  }
102  else if( rfield.range[*nqh][0] > rfield.egamry || rfield.range[*nqh][1] >
103  rfield.egamry )
104  {
105  fprintf( ioQQQ, " One of the energies is too high, outside the range of the code.\n" );
106  cdEXIT(EXIT_FAILURE);
107  }
108  }
109 
110  /* >>chng 06 mar 22, add time option to vary only some continua with time */
111  if( nMatch( "TIME" , chCard ) )
112  rfield.lgTimeVary[*nqh] = true;
113 
114  /* vary option */
115  if( optimize.lgVarOn )
116  {
117  /* pointer to where to write */
119  if( lgAoxOn )
120  {
121  /* this is the number of parameters to feed onto the input line */
123  /* vary alpha ox */
124  strcpy( optimize.chVarFmt[optimize.nparm], "RATIO alphox %f" );
125  /* param is linear scale factor */
126  optimize.vparm[0][optimize.nparm] = (realnum)aox;
127  optimize.vincr[optimize.nparm] = 0.2f;
128  }
129  else
130  {
131  /* this is the number of parameters to feed onto the input line */
133  strcpy( optimize.chVarFmt[optimize.nparm], "RATIO LOG %f %f %f" );
134  /* param is log of abundance by number relative to hydrogen */
135  optimize.vparm[0][optimize.nparm] = (realnum)log10(rfield.totpow[*nqh]);
136  optimize.vparm[1][optimize.nparm] = (realnum)rfield.range[*nqh][0];
137  optimize.vparm[2][optimize.nparm] = (realnum)rfield.range[*nqh][1];
138  optimize.vincr[optimize.nparm] = 0.2f;
139  }
140  ++optimize.nparm;
141  }
142 
143  ++*nqh;
144  if( *nqh >= LIMSPC )
145  {
146  fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" );
147  cdEXIT(EXIT_FAILURE);
148  }
149 
150  return;
151 }
152 #if defined(__HP_aCC)
153 #pragma OPTIMIZE OFF
154 #pragma OPTIMIZE ON
155 #endif

Generated for cloudy by doxygen 1.8.1.1