cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse_species.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #include "cddefines.h"
5 #include "parse_species.h"
6 
7 #include "parser.h"
8 #include "mole.h"
9 #include "species.h"
10 
11 // This file groups the handler for the species command with the
12 // routines which interpret the options. It would be better if this
13 // were done in just one routine, to allow the code to warn on invalid
14 // options rather than just ignore them
15 
17 {
18  DEBUG_ENTRY( "ParseSpecies()" );
19  string chString_quotes_original;
20  bool lgQuotesFound = true;
21  if (p.GetQuote(chString_quotes_original))
22  lgQuotesFound = false;
23 
24  if( ! lgQuotesFound )
25  {
26  fprintf(ioQQQ,"Need to provide species name to SPECIES command.\n"
27  "The previous SPECIES command has been renamed DATABASE -- did you mean to use that?\n");
29  }
30 
31  // Break up the remainder of the input line into options and (optionally) values
32  // String or numeric values can be given without an '=', named options require '='
33  Symbol s=p.getSymbol();
34  while(1)
35  {
36  if (s.toktype == Symbol::EOSTAT)
37  {
38  break;
39  }
40  if ( s.toktype != Symbol::NAME )
41  {
42  fprintf(ioQQQ,"Value %s not understood\n",s.value.c_str());
44  }
45  Symbol t=p.getSymbol();
46  if (t.toktype == Symbol::EOSTAT || t.toktype == Symbol::NAME)
47  {
48  mole_global.speciesProperties[chString_quotes_original].p.push_back(
49  pair<string,count_ptr<Option> >(s.value,count_ptr<Option>(new Option(true))));
50  s = t;
51  }
52  else if (t.toktype == Symbol::NUMBER)
53  {
54  long num = strtol(t.value.c_str(),NULL,10);
55  mole_global.speciesProperties[chString_quotes_original].p.push_back(
56  pair<string,count_ptr<Option> >(s.value,count_ptr<Option>(new Option(num))));
57  s = p.getSymbol();
58  }
59  else if (t.toktype == Symbol::STRING)
60  {
61  mole_global.speciesProperties[chString_quotes_original].p.push_back(
63  s = p.getSymbol();
64  }
65  else if (t.toktype == Symbol::OPERATOR && t.value == "=")
66  {
67  t = p.getSymbol();
68  if (t.toktype == Symbol::NAME)
69  {
70  mole_global.speciesProperties[chString_quotes_original].p.push_back(
72  }
73  else if (t.toktype == Symbol::STRING)
74  {
75  mole_global.speciesProperties[chString_quotes_original].p.push_back(
77  }
78  else if (t.toktype == Symbol::NUMBER)
79  {
80  long num = strtol(t.value.c_str(),NULL,10);
81  mole_global.speciesProperties[chString_quotes_original].p.push_back(
82  pair<string,count_ptr<Option> >(s.value,count_ptr<Option>(new Option(num))));
83  }
84  else
85  {
86  fprintf(ioQQQ,"Option '%s' value '%s' not understood\n",s.value.c_str(),t.value.c_str());
87  fprintf(ioQQQ,"WARNING: This usage of the SPECIES command was not understood.\n"
88  "The previous SPECIES command has been renamed DATABASE -- did you mean to use that?\n");
90  }
91  s = p.getSymbol();
92  }
93  else
94  {
95  fprintf(ioQQQ,"Option '%s' not understood\n",s.value.c_str());
96  fprintf(ioQQQ,"WARNING: This usage of the SPECIES command was not understood.\n"
97  "The previous SPECIES command has been renamed DATABASE -- did you mean to use that?\n");
99  }
100  }
101 }
102 
104 {
105  DEBUG_ENTRY("setProperties()");
106  char chLabelChemical[CHARS_SPECIES];
107  if( sp.lgMolecular )
108  {
109  strcpy( chLabelChemical, sp.chLabel );
110  }
111  else
112  {
113  long nelem = 0, IonStg;
114  parsespect(sp.chLabel,nelem,IonStg);
115  makeChemical(chLabelChemical, nelem, IonStg-1);
116  }
117 
118  map<string,Properties >::iterator props =
119  mole_global.speciesProperties.find(chLabelChemical);
120  if (props == mole_global.speciesProperties.end())
121  return;
122 
123  props->second.setDone();
124 
125  for(vector<pair<string,count_ptr<Option> > >::iterator prop=props->second.p.begin();
126  prop!=props->second.p.end();++prop)
127  {
128  if (prop->first == "LEVELS")
129  {
130  if (prop->second->opttype == Option::LONG)
131  {
132  if (prop->second->i > sp.numLevels_max)
133  {
134  fprintf(ioQQQ,"Species '%s', %ld levels requested, only %ld available. Using all.\n",
135  chLabelChemical,prop->second->i,
136  sp.numLevels_max);
137  sp.setLevels = sp.numLevels_max;
138  }
139  else
140  {
141  sp.setLevels = prop->second->i;
142  }
143  }
144  else if (prop->second->opttype == Option::OPTION && prop->second->s == "ALL")
145  {
146  sp.setLevels = sp.numLevels_max;
147  }
148  else
149  {
150  fprintf(ioQQQ,"Incorrect type for 'LEVELS' option to species\n"
151  "Expecting 'LEVELS <number>', 'LEVELS=<number>' or 'LEVELS=ALL'\n");
152  }
153  }
154  else if (prop->first == "LTE")
155  {
156  if (prop->second->opttype == Option::BOOL)
157  {
158  sp.lgLTE = prop->second->l;
159  }
160  else
161  {
162  fprintf(ioQQQ,"Incorrect type for 'LTE' option to species\n");
163  }
164  }
165  else if (prop->first == "OFF")
166  {
167  ; // Do nothing, already handled
168  }
169  else
170  {
171  fprintf(ioQQQ,"Option '%s' not understood for species '%s'\n",
172  prop->first.c_str(),sp.chLabel);
174  }
175  }
176 }
177 
179 {
180  for (map<string,Properties>::iterator props =
182  props != mole_global.speciesProperties.end();
183  ++props)
184  {
185  if (! props->second.isDone())
186  {
187  fprintf(ioQQQ,"\n\nWarning: SPECIES \"%s\" command has no effect since species not found.\n"
188  "Is species inactive or misspelt? Names of species are case-sensitive. Consult species list in docs/SpeciesLabels.txt.\n\n",
189  props->first.c_str());
190  }
191  }
192 }
193 
194 bool speciesOff(const string& label)
195 {
196  map<string,Properties>::iterator props =
197  mole_global.speciesProperties.find(label);
198  if (props != mole_global.speciesProperties.end())
199  {
200  props->second.setDone();
201 
202  for(vector<pair<string,count_ptr<Option> > >::iterator prop=props->second.p.begin();
203  prop!=props->second.p.end();++prop)
204  {
205  if (prop->first == "OFF")
206  {
207  if (prop->second->opttype != Option::BOOL)
208  {
209  fprintf(ioQQQ,"Incorrect type for 'OFF' option to species\n");
210  }
211 
212  if (prop->second->l || prop->second->opttype != Option::BOOL)
213  {
214  return true;
215  }
216  }
217  }
218  }
219  return false;
220 }
t_mole_global mole_global
Definition: mole.cpp:7
int GetQuote(string &chLabel)
Definition: parser.cpp:213
bool speciesOff(const string &label)
FILE * ioQQQ
Definition: cddefines.cpp:7
Definition: parser.h:43
Symbol getSymbol()
Definition: parser.cpp:824
long setLevels
Definition: species.h:46
void ParseSpecies(Parser &p)
void setProperties(species &sp)
#define EXIT_FAILURE
Definition: cddefines.h:168
#define cdEXIT(FAIL)
Definition: cddefines.h:482
void speciesCheck()
void parsespect(char *chLabel, long &nelem, long &IonStg)
Definition: species.cpp:900
char * chLabel
Definition: species.h:38
string makeChemical(long nelem, long ion)
Definition: species.cpp:929
Definition: parser.h:545
long numLevels_max
Definition: species.h:44
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
bool lgMolecular
Definition: species.h:56
string value
Definition: parser.h:38
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
map< string, Properties > speciesProperties
Definition: mole.h:368
enum tokens toktype
Definition: parser.h:37
Definition: parser.h:34
bool lgLTE
Definition: species.h:68