Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parser.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2023 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef PARSER_H_
5 #define PARSER_H_
6 
13 #include "service.h"
14 #include "thirdparty.h"
15 
16 const char * nWord(const char *chKey,
17  const char *chCard);
18 
19 class Parser;
20 class DepthTable;
21 class LineID;
22 
23 typedef void (*OptionParser)(Parser &);
24 
25 struct CloudyCommand {
26  const char *name;
28 };
29 
30 bool isBoundaryChar(char c);
31 
32 class Symbol {
33 public:
36  string value;
37  Symbol(enum tokens t, const string& v) : toktype(t), value(v) {}
38 };
39 
41 class Parser
42 {
43  string m_card; // all-caps version of m_card_raw
44  string m_card_raw; // raw input line with all comments stripped
45  string m_card_comment; // input line with visible comments included, used for output
46  long int m_len;
47  long int m_off;
48  bool m_lgEOL;
49  const CloudyCommand * const m_Commands;
50  std::map<string,double> m_symtab;
51  std::map<string,size_t> m_uniqueLen;
52 public:
53  long int m_nqh;
55 
56  explicit Parser(void) : m_Commands(NULL)
57  {
58  init();
59  }
60  explicit Parser(const CloudyCommand *commands) : m_Commands(commands)
61  {
62  init();
63  }
64 private:
65  void init()
66  {
67  m_nqh = 0;
68  m_lgDSet = m_lgEOF = false;
69  setline("");
70  if( m_Commands != NULL )
71  {
72  trieNode* root = new trieNode;
73  for( size_t i=0; m_Commands[i].name != NULL; ++i )
74  insertToken(root, m_Commands[i].name);
75  for( size_t i=0; m_Commands[i].name != NULL; ++i )
76  {
77  size_t ul = findUniqueLen(root, m_Commands[i].name);
78  if( ul < 4 )
79  ul = min(strlen(m_Commands[i].name),4);
80  m_uniqueLen[m_Commands[i].name] = ul;
81  }
82  delete root;
83  }
84  }
85  void newlineProcess();
86  bool at_end() const;
87  char current( void ) const
88  {
89  return m_card[m_off];
90  }
91  char current_raw() const;
92  void skip_whitespace();
93  string m_getCommandToken() const;
94  size_t m_getUniqueLen(const string& s2) const
95  {
96  size_t uniqueLen;
97  auto p = m_uniqueLen.find(s2);
98  if( p == m_uniqueLen.end() )
99  uniqueLen = s2.length();
100  else
101  uniqueLen = p->second;
102  return uniqueLen;
103  }
104 public:
105  bool getline();
106  void setline(const string& card);
107  void set_point(long int ipnt)
108  {
109  m_off = ipnt;
110  }
111  const char * nWord(const char *chKey) const;
112  bool lgReachedEnd();
113  void showLocation(FILE *io = ioQQQ) const;
114 public:
115  long int GetElem( void ) const;
116  double FFmtRead( void );
117  double getNumberPlain( const char *chDesc );
118  double getNumberCheck( const char *chDesc );
119  double getNumberDefault( const char *chDesc, double fdef );
120  double getNumberCheckLogLinNegImplLog( const char *chDesc );
121  double getNumberCheckAlwaysLog( const char *chDesc );
122  double getNumberCheckAlwaysLogLim( const char *chDesc, double flim );
123  double getNumberDefaultAlwaysLog( const char *chDesc, double fdef );
124  double getNumberDefaultNegImplLog( const char *chDesc, double fdef );
125  bool lgEOL(void) const
126  {
127  return m_lgEOL;
128  }
129  void setEOL(bool val)
130  {
131  m_lgEOL = val;
132  }
133  NORETURN void NoNumb(const char *chDesc) const;
134 private:
135  int nMatch1(const char *chKey) const
136  {
137  const char *p=chKey;
138 
139  while (isspace(*p))
140  ++p;
141 
142  for (const char *q=p; *q; ++q)
143  ASSERT(!islower(*q));
144 
145  if ( !isBoundaryChar(*p))
146  {
147  const char *c = m_card.c_str();
148  const char *q = ::nWord(p, c);
149  if (NULL == q)
150  return 0;
151  else
152  return q-c+1;
153  }
154  else
155  {
156  // If the keyword starts with a member of the boundary character
157  // set, can't require it to be preceded by one so revert to explicit
158  // matching
159  return ::nMatch(chKey, m_card.c_str());
160  }
161  }
162 public:
163  bool nMatch(const char *chKey) const
164  {
165  return nMatch1(chKey) != 0;
166  }
167  bool GetParam(const char *chKey, double *val)
168  {
169  int i = nMatch1(chKey);
170  if (i > 0) {
171  m_off = i-1;
172  *val = FFmtRead();
173  }
174  return i>0;
175  }
176  bool GetRange(const char *chKey, double *val1, double *val2)
177  {
178  int i = nMatch1(chKey);
179  if (i > 0) {
180  m_off = i-1;
181  *val1 = FFmtRead();
182  *val2 = FFmtRead();
183  }
184  return i>0;
185  }
186  bool nMatchErase(const char *chKey)
187  {
188  const char *p=chKey;
189  while (isspace(*p))
190  ++p;
191  int i = nMatch1(p);
192  bool found = (i != 0);
193  if(found)
194  {
195  const long len = strlen(p);
196  /* erase this keyword, it upsets FFmtRead */
197  for (long j=0; j<len; ++j)
198  {
199  m_card[i+j-1] = ' ';
200  }
201  }
202  return found;
203  }
204  bool hasCommand(const string& s2);
205  bool peekNextCommand(const string& s2);
206  bool Command(const char *name, OptionParser doOpts)
207  {
208  bool lgFound = hasCommand(name);
209  if ( lgFound )
210  (*doOpts)(*this);
211  return lgFound;
212  }
213  string ClosestMatch(const string& token) const;
214  bool isComment(void) const;
215  bool isVar(void) const;
216  std::string getVarName(void);
217  void doSetVar(void);
218  void echo(void) const;
219  bool last(void) const;
220  int PrintLine(FILE *fp) const
221  {
222  return fprintf( fp, " ==%-.80s==\n", m_card_comment.c_str());
223  }
224  NORETURN void CommandError( void ) const;
225  NORETURN void Error( const char *msg ) const;
226  NORETURN void StringError( ) const;
227  int GetQuote( string& chLabel );
228  const char *StandardEnergyUnit(void) const;
229  string StandardFluxUnit(void) const;
230  string getFirstChunk(long i);
231  string getFirstChunkRaw(long i);
232  string getRawTail()
233  {
234  return m_card_raw.substr(m_off);
235  }
236  void help(FILE *fp) const;
237  double getWave();
238  double getWaveOpt();
239  LineID getLineID(bool lgAtStart=true);
240  Symbol getSymbol();
241  int getElement();
242  void getPairs(vector<double>& a, vector<double> & b);
243  void readList(vector<string>& list, const char *chName);
244  void readLaw(DepthTable& table);
245 };
246 
247 // helper functions for the DataParser class, do not call these directly
248 template<typename T>
249 inline void getTokenOptionalImpl(istringstream& iss, const string&, T& var)
250 {
251  iss >> var;
252  if( iss.fail() )
253  var = T();
254 }
255 
256 // optimized specializations for the most common types
257 template<>
258 inline void getTokenOptionalImpl(istringstream& iss, const string& s, double& var)
259 {
260  FPRead(iss, s, var);
261 }
262 
263 template<>
264 inline void getTokenOptionalImpl(istringstream& iss, const string& s, sys_float& var)
265 {
266  FPRead(iss, s, var);
267 }
268 
269 template<>
270 inline void getTokenOptionalImpl(istringstream& iss, const string& s, long long& var)
271 {
272  IntRead(iss, s, var);
273 }
274 
275 template<>
276 inline void getTokenOptionalImpl(istringstream& iss, const string& s, unsigned long long& var)
277 {
278  IntRead(iss, s, var);
279 }
280 
281 template<>
282 inline void getTokenOptionalImpl(istringstream& iss, const string& s, long& var)
283 {
284  IntRead(iss, s, var);
285 }
286 
287 template<>
288 inline void getTokenOptionalImpl(istringstream& iss, const string& s, unsigned long& var)
289 {
290  IntRead(iss, s, var);
291 }
292 
293 template<>
294 inline void getTokenOptionalImpl(istringstream& iss, const string& s, int& var)
295 {
296  IntRead(iss, s, var);
297 }
298 
299 template<>
300 inline void getTokenOptionalImpl(istringstream& iss, const string& s, unsigned int& var)
301 {
302  IntRead(iss, s, var);
303 }
304 
310 
312 
313 class DataParser {
314  string p_filename;
315  fstream p_io;
317  string p_line;
318  size_t p_nr;
319  istringstream p_ls;
320  bool p_lgEOF;
321 
322  void p_open(const string& name, eod_style es, access_scheme as);
323  void p_close();
324  // prepare a recently obtained line for parsing
325  void p_newlineProcess();
326  // returns true if the current line is concidered comment only
327  bool p_isComment() const
328  {
329  if( p_es == ES_NONE || p_es == ES_STARS_ONLY )
330  return ( p_blankLine() || p_line[0] == '#' );
331  else if( p_es == ES_STARS_AND_BLANKS )
332  return ( p_line[0] == '#' );
333  else
334  TotalInsanity();
335  }
336  // returns true if the line contains only whitespace, possibly followed by a comment
337  // NB NB -- this routine returns false if the comment character is in column 0...
338  // this is needed because comments starting in column 0 may have a different meaning
339  // than blank lines, depending on the value of p_es...
340  bool p_blankLine() const
341  {
342  for( size_t i=0; i < p_line.length(); ++i )
343  {
344  if( i > 0 && p_line[i] == '#' )
345  return true;
346  else if( !isspace(p_line[i]) )
347  return false;
348  }
349  return true;
350  }
351  // get the position on the current line
352  size_t p_pos()
353  {
354  long p = p_ls.tellg();
355  if( p < 0 )
356  return p_line.length();
357  else
358  return size_t(p);
359  }
360  // set the position on the current line (i.e. skip to position p)
361  void p_pos(size_t p)
362  {
363  p_ls.seekg(p);
364  if( p >= p_line.length() )
365  p_ls.setstate(ios_base::eofbit);
366  }
367  // skip whitespace on the current line
368  void p_skipWS()
369  {
370  while( p_ls.good() )
371  {
372  char c = p_ls.peek();
373  if( !isspace(c) )
374  break;
375  (void)p_ls.get();
376  }
377  }
378  bool p_isSeparator(char c)
379  {
380  return ( c == '=' || c == ',' );
381  }
382  // replace separators with spaces
384  {
385  bool lgModified = false;
386  for( size_t i=0; i < p_line.length(); ++i )
387  if( p_isSeparator(p_line[i]) )
388  {
389  p_line[i] = ' ';
390  lgModified = true;
391  }
392  if( lgModified )
393  p_ls.str(p_line);
394  }
395  // helper routine showing where parsing stopped
396  void p_showLocation(size_t p, FILE *io);
397  // this implements reading a quoted string
398  void p_getQuoteOptional(string& str);
399 public:
400  // default constructor
401  DataParser() : p_es(ES_INVALID), p_nr(0), p_lgEOF(false) {}
402  // constructor
403  // name: the name of the data file to be read
404  // es: which inline EOD markers are allowed? (see also above)
405  // as: access scheme for searching the data file (see cpu.h)
406  DataParser(const string& name, eod_style es, access_scheme as = AS_DEFAULT)
407  {
408  p_open(name, es, as);
409  }
410  // open data file for parsing, normally done via ctor
411  void open(const string& name, eod_style es, access_scheme as = AS_DEFAULT)
412  {
413  p_close();
414  p_open(name, es, as);
415  }
416  // close data file, normally done via dtor
417  void close()
418  {
419  p_close();
420  }
421  // check whether opening the file succeeded, only relevant for optional access schemes
422  bool isOpen() const { return p_io.is_open(); }
423  // check magic number, aborts if mismatch is found
424  void checkMagic(long i0);
425  void checkMagic(long i0, long i1);
426  void checkMagic(long i0, long i1, long i2);
427  void checkMagic(long i0, long i1, long i2, long i3);
428  // read next non-comment line, returns false on EOF or failure
429  bool getline();
430  // feed a data line to the parser
431  void setline(const string& line)
432  {
433  p_line = line;
435  }
436  // try to read optional token, returns false if operation failed
437  template<typename T>
438  bool getTokenOptional(T& var)
439  {
441  if( p_ls.fail() )
442  return false;
443  else if( !isspace(p_ls.peek()) && !p_ls.eof() )
444  errorAbort("found trailing junk after token");
445  else
446  return true;
447  }
448  // try to read vector of optional tokens, returns number of tokens read successfully
449  template<typename T>
450  size_t getTokenOptional(T var[], size_t n)
451  {
452  static_assert( !SameType<T,char>::value &&
455  "Reading C-style strings is not supported, use C++ strings instead." );
456  for( size_t i=0; i < n; ++i )
457  {
458  if( !getTokenOptional(var[i]) )
459  return i;
460  }
461  return n;
462  }
463  // read token, will abort on failure
464  template<typename T>
465  void getToken(T& var)
466  {
467  if( !getTokenOptional(var) )
468  errorAbort("failed to read valid data");
469  }
470  // read vector of tokens, will abort on failure
471  template<typename T>
472  void getToken(T var[], size_t n)
473  {
474  static_assert( !SameType<T,char>::value &&
477  "Reading C-style strings is not supported, use C++ strings instead." );
478  for( size_t i=0; i < n; ++i )
479  getToken(var[i]);
480  }
481  // read an optional quoted string
482  bool getQuoteOptional(string& str)
483  {
484  p_getQuoteOptional(str);
485  if( p_ls.fail() )
486  return false;
487  else if( !isspace(p_ls.peek()) && !p_ls.eof() )
488  errorAbort("found trailing junk after token");
489  else
490  return true;
491  }
492  // read a quoted string
493  void getQuote(string& str)
494  {
495  if( !getQuoteOptional(str) )
496  errorAbort("failed to read a quoted string");
497  }
498  // read an optional keyword
499  bool getKeywordOptional(string& str)
500  {
501  bool lgSuccess = getTokenOptional(str);
502  caps(str);
503  return lgSuccess;
504  }
505  // read a keyword
506  void getKeyword(string& str)
507  {
508  if( !getKeywordOptional(str) )
509  errorAbort("failed to read a keyword");
510  }
511  // read line label plus wavelength
512  void getLineID(LineID& line);
513  // skip to a specified position on the line
514  void skipTo(size_t p)
515  {
516  if( p < p_pos() )
517  errorAbort("skipping to requested position failed");
518  p_pos(p);
519  }
520  // skip to the first position just after the next instance of a specified string
521  void skipAfter(const string& s)
522  {
523  auto cp = p_pos();
524  auto p = p_line.substr(cp).find(s);
525  if( p != string::npos )
526  skipTo(cp + p + s.length());
527  else
528  {
529  ostringstream oss;
530  oss << "skipAfter could not find string =" << s << "=";
531  errorAbort(oss.str());
532  }
533  }
534  // returns true if the end of the line is reached
535  bool lgEOL()
536  {
537  // skipping whitespace allows the trailing junk to be shown
538  // correctly by showLocation() if the test for EOL fails...
539  p_skipWS();
540  return p_ls.eof();
541  }
542  // check if EOL is reached and abort if this is not the case
543  void checkEOL()
544  {
545  if( !lgEOL() )
546  errorAbort("found trailing junk at the end of this line");
547  }
548  // returns true if the end of the file is reached
549  bool lgEOF() const { return p_lgEOF; }
550  // returns true if the current line is an inline end-of-data marker
551  bool lgEODMarker() const;
552  // check if EOD is reached and abort if this is not the case
553  void checkEOD()
554  {
555  if( getline() && !lgEODMarker() )
556  errorAbort("found surplus input at the end of this file");
557  }
558  // get the current position in the stream buffer
559  long getpos() { return p_io.tellg(); }
560  // jump to specific position in the stream buffer (previously returned by getpos())
561  void setpos(long pos) { p_io.seekg(pos, p_io.beg); }
562  // CODE SMELL -- rewind file to the beginning
563  void rewind()
564  {
565  p_io.clear();
566  p_io.seekg(0);
567  p_line.clear();
568  p_nr = 0;
569  p_ls.str("");
570  p_ls.clear();
571  p_lgEOF = false;
572  }
573  // abort with specific error message
574  NORETURN void errorAbort(const string& msg, FILE *io = ioQQQ);
575  // non-fatal warning message
576  void warning(const string& msg, FILE *io = ioQQQ);
577 };
578 
580 template <typename V>
581 class KeyAction {
582  const char * const m_keyword;
584 public:
585  KeyAction(const char *keyword, const V &action) :
586  m_keyword(keyword), m_action(action) {}
587 
588  const char *key(void) const
589  {
590  return m_keyword;
591  }
592  void operator()(realnum *v) const
593  {
594  m_action(v);
595  }
596 };
597 
599 template <typename V>
600 inline KeyAction<V> MakeKeyAction(const char *keyword, const V &action)
601 {
602  return KeyAction<V>(keyword, action);
603 }
604 
607 {
609 public:
610  UnitConverter ( double unit ) : m_unit((realnum)unit) {}
611 
612  void operator()( realnum *t ) const
613  {
614  *t *= m_unit;
615  }
616 };
617 
620 template <typename T, typename V>
621 bool parserProcess(Parser &p, T *list, unsigned long nlist, V *value)
622 {
623  bool lgFound = false;
624  for (unsigned long option=0; option < nlist; ++option)
625  {
626  if( p.nWord( list[option].key() ) )
627  {
628  list[option]( value );
629  lgFound = true;
630  break;
631  }
632  }
633  return lgFound;
634 }
635 
639 void ParseCosmicRays( Parser &p );
640 
644 void ParseCosmology( Parser &p );
645 
651 
652 void ParseAbundances(Parser &p);
653 
655 void ParseDont(Parser &p);
656 
660 void ParseSave(Parser &p);
661 
662 void parse_save_line(Parser &p,
663  /* true, return rel intensity, false, log of luminosity or intensity I */
664  bool lgLog3,
665  ostringstream& chHeader,
666  long int ipPun
667 );
668 
669 void parse_save_average(Parser &p,
670  /* the file we will write to */
671  long int ipPun,
672  ostringstream& chHeader);
673 
674 void parse_save_colden(Parser &p,
675  /* the header for the file, a list of identifications */
676  ostringstream& chHeader);
677 
678 void Parse_Save_Line_RT(Parser &p);
679 
681 void ParseAge(Parser &p);
682 
686 void ParseAgn(Parser &p);
687 
693 void ParseBlackbody(Parser &p);
694 
698 void ParseCompile(Parser &p );
699 
701 void ParseConstant(Parser &p);
702 
706 void ParseDLaw(Parser &p );
707 
711 void ParseTLaw(Parser &p);
712 
717 void ParseGrain(Parser &p);
718 
720 void ParseFluc(Parser &p);
721 
723 void ParseHDEN(Parser &p);
724 
729 void ParseDatabaseISO(long ipISO, Parser &p);
730 
734 void ParseDatabaseH2(Parser &p );
735 
739 void ParseGrid(Parser &p);
740 
742 void ParseInit(Parser &p);
743 
745 void ParseInitFile(const string& chName);
746 
751 void ParseInterp(Parser &p);
752 
758 void ParseIonParI(Parser &p);
759 
766 void ParseIonParX(Parser &p);
772 void ParseIonPar(Parser &p,
773  char chType);
774 
778 void ParseNorm(Parser &p);
779 
783 void ParseOptimize(Parser &p);
784 
788 void ParsePrint(Parser &p );
789 
791 void ParseRadius(Parser &p);
792 
794 void ParseSet(Parser &p);
795 
801 void ParseTable(Parser &p);
802 
804 void ParseTrace(Parser &p);
805 
806 /*ParseExtinguish parse the extinguish command */
807 void ParseExtinguish( Parser &p );
808 
809 /*ParseIlluminate parse the illuminate command */
810 void ParseIlluminate( Parser &p );
811 
812 /*ParseCaseB - parse the Case B command */
813 void ParseCaseB(Parser &p );
814 
816 void ParseTest(Parser &p);
817 
819 void ParseAbsMag(Parser &p);
820 
822 void ParseBackgrd(Parser &p);
823 
825 void ParseCoronal(Parser &p);
826 
828 void ParseElement(Parser &p);
829 
835 void ParseCMB(double z,
836  long int *nqh);
837 
845 void ParseF_nu(
846  Parser &p,
847  const char *chType,
848  bool lgNU2);
849 
853 void ParseGlobule(Parser &p);
854 
856 void ParseRangeOption(Parser &p);
857 
859 void ParseMap(Parser &p);
860 
862 void ParseMetal(Parser &p);
863 
864 void ParseLineList(Parser &p, vector<LineID>& lines);
865 
866 void ParsePrtLineSum(Parser &p);
867 
870 
872 void ParseRatio(Parser &p);
873 
875 void ParseSphere(Parser &p);
876 
878 void ParseStop(Parser &p);
879 
883 void ParseCrashDo(Parser &p);
884 
885 class Option {
886 public:
889  union {
890  bool l;
891  long i;
892  double r;
893  };
894  string s;
895  Option(bool val)
896  {
897  opttype=BOOL;
898  l = val;
899  }
900  Option(long val)
901  {
902  opttype=LONG;
903  i = val;
904  }
905  Option(double val)
906  {
907  opttype=REAL;
908  r = val;
909  }
910  Option(const string& val, enum Quoted q)
911  {
912  if (q == QUOTED)
913  opttype=STRING;
914  else
915  opttype=OPTION;
916  s = val;
917  }
918 };
919 
921 {
922  bool m_lgDone;
923 public:
924  vector< pair<string, shared_ptr<Option> > > p;
925  Properties() : m_lgDone(false) {}
926  void setDone()
927  {
928  m_lgDone = true;
929  }
930  bool isDone() const
931  {
932  return m_lgDone;
933  }
934 };
935 
936 #endif // _PARSER_H_
bool lgEOF() const
Definition: parser.h:549
void checkEOD()
Definition: parser.h:553
Definition: parser.h:311
void Parse_Save_Line_RT(Parser &p)
Definition: save_line.cpp:207
Definition: cpu.h:445
void setEOL(bool val)
Definition: parser.h:129
bool nMatch(const char *chKey) const
Definition: parser.h:163
void parse_save_average(Parser &p, long int ipPun, ostringstream &chHeader)
Definition: save_average.cpp:11
Definition: parser.h:34
Definition: cpu.h:257
const realnum m_unit
Definition: parser.h:608
void(* OptionParser)(Parser &)
Definition: parser.h:23
Definition: parser.h:887
Definition: parser.h:888
void getTokenOptionalImpl(istringstream &iss, const string &, T &var)
Definition: parser.h:249
STATIC long int ipPun
Definition: save_do.cpp:368
void echo(void) const
Definition: parser.cpp:194
void ParseCosmology(Parser &p)
Definition: parse_cosmology.cpp:9
bool peekNextCommand(const string &s2)
Definition: parser.cpp:847
double FFmtRead(void)
Definition: parser.cpp:487
#define NORETURN
Definition: cpu.h:461
void ParseIonParX(Parser &p)
Definition: parse_ionpar.cpp:15
Definition: parser.h:887
NORETURN void TotalInsanity(void)
Definition: service.cpp:1174
void setline(const string &card)
Definition: parser.cpp:287
void getToken(T &var)
Definition: parser.h:465
Option(double val)
Definition: parser.h:905
double getNumberCheckLogLinNegImplLog(const char *chDesc)
Definition: parser.cpp:425
Parser(void)
Definition: parser.h:56
bool m_lgEOL
Definition: parser.h:48
bool Command(const char *name, OptionParser doOpts)
Definition: parser.h:206
long int m_nqh
Definition: parser.h:53
Definition: parser.h:34
void ParseDatabaseH2(Parser &p)
Definition: parse_atom_h2.cpp:10
void operator()(realnum *t) const
Definition: parser.h:612
void readList(vector< string > &list, const char *chName)
Definition: parser.cpp:1112
Properties()
Definition: parser.h:925
eod_style p_es
stream for reading data file
Definition: parser.h:316
void ParseRangeOption(Parser &p)
Definition: parse_rangeoption.cpp:8
bool lgReachedEnd()
Definition: parser.cpp:114
size_t getTokenOptional(T var[], size_t n)
Definition: parser.h:450
string p_filename
Definition: parser.h:314
long nMatch(const char *chKey, const char *chCard)
Definition: service.cpp:728
void ParseLineList(Parser &p, vector< LineID > &lines)
Definition: prt_linesum.cpp:14
void skip_whitespace()
Definition: parser.cpp:45
int GetQuote(string &chLabel)
Definition: parser.cpp:218
access_scheme
Definition: cpu.h:257
void getQuote(string &str)
Definition: parser.h:493
bool getTokenOptional(T &var)
Definition: parser.h:438
Definition: parser.h:311
bool at_end() const
Definition: parser.cpp:37
Symbol(enum tokens t, const string &v)
Definition: parser.h:37
void newlineProcess()
Definition: parser.cpp:50
double getNumberDefaultAlwaysLog(const char *chDesc, double fdef)
Definition: parser.cpp:461
bool nMatchErase(const char *chKey)
Definition: parser.h:186
void ParseHDEN(Parser &p)
Definition: parse_hden.cpp:10
void insertToken(trieNode *root, const string &token)
Definition: thirdparty.cpp:5129
void setline(const string &line)
Definition: parser.h:431
LineID getLineID(bool lgAtStart=true)
Definition: parser.cpp:599
long int m_off
Definition: parser.h:47
Definition: parser.h:887
Definition: lines.h:14
void ParseElement(Parser &p)
Definition: parse_element.cpp:17
void ParseTest(Parser &p)
Definition: parse_test.cpp:20
eod_style
Definition: parser.h:311
bool parserProcess(Parser &p, T *list, unsigned long nlist, V *value)
Definition: parser.h:621
FILE * ioQQQ
Definition: cddefines.cpp:7
void parse_save_line(Parser &p, bool lgLog3, ostringstream &chHeader, long int ipPun)
double getWave()
Definition: parser.cpp:394
string s
Definition: parser.h:894
size_t p_pos()
Definition: parser.h:352
void FPRead(istringstream &iss, const string &s, double &value)
Definition: service.cpp:548
const char * name
Definition: parser.h:26
Definition: parser.h:41
bool lgEODMarker() const
Definition: parser.cpp:1447
Symbol getSymbol()
Definition: parser.cpp:987
void ParseRadius(Parser &p)
Definition: parse_radius.cpp:13
int getElement()
Definition: parser.cpp:899
size_t p_nr
the current line being read
Definition: parser.h:318
bool isBoundaryChar(char c)
Definition: parser.cpp:135
NORETURN void StringError() const
Definition: parser.cpp:208
double getNumberPlain(const char *chDesc)
Definition: parser.cpp:403
bool m_lgDone
Definition: parser.h:922
Definition: parser.h:34
bool isDone() const
Definition: parser.h:930
void lines(void)
Definition: prt_lines.cpp:56
void ParseCaseB(Parser &p)
Definition: parse_caseb.cpp:9
void ParseGrain(Parser &p)
Definition: parse_grain.cpp:12
void rewind()
Definition: parser.h:563
string ClosestMatch(const string &token) const
Definition: parser.cpp:862
Definition: parser.h:887
Definition: parser.h:34
void p_skipWS()
Definition: parser.h:368
void ParseExtinguish(Parser &p)
Definition: parse_extinguish.cpp:9
void setpos(long pos)
Definition: parser.h:561
OptionParser action
Definition: parser.h:27
Definition: parser.h:887
void getToken(T var[], size_t n)
Definition: parser.h:472
istringstream p_ls
number of the line we are parsing
Definition: parser.h:319
void p_showLocation(size_t p, FILE *io)
Definition: parser.cpp:1240
void IntRead(istringstream &iss, const string &s, long long &value)
Definition: service.cpp:649
string StandardFluxUnit(void) const
Definition: parser.cpp:305
Option(long val)
Definition: parser.h:900
size_t findUniqueLen(trieNode *root, const string &token)
Definition: thirdparty.cpp:5153
void ParseSave(Parser &p)
Definition: parse_save.cpp:85
bool lgEOL()
Definition: parser.h:535
string getRawTail()
Definition: parser.h:232
Quoted
Definition: parser.h:888
size_t m_getUniqueLen(const string &s2) const
Definition: parser.h:94
const char * nWord(const char *chKey, const char *chCard)
Definition: parser.cpp:67
void ParseTable(Parser &p)
Definition: parse_table.cpp:94
bool m_lgDSet
Definition: parser.h:54
void set_point(long int ipnt)
Definition: parser.h:107
void getLineID(LineID &line)
Definition: parser.cpp:1359
Opts
Definition: parser.h:887
Definition: parser.h:311
void ParseAgn(Parser &p)
Definition: parse_agn.cpp:10
void init()
Definition: parser.h:65
void warning(const string &msg, FILE *io=ioQQQ)
Definition: parser.cpp:1475
Definition: parser.h:25
Definition: parser.h:34
void ParseDatabaseISO(long ipISO, Parser &p)
Definition: parse_atom_iso.cpp:16
void operator()(realnum *v) const
Definition: parser.h:592
Option(bool val)
Definition: parser.h:895
NORETURN void errorAbort(const string &msg, FILE *io=ioQQQ)
Definition: parser.cpp:1461
void showLocation(FILE *io=ioQQQ) const
Definition: parser.cpp:120
void ParsePowerlawContinuum(Parser &p)
Definition: parse_powerlawcontinuum.cpp:10
float realnum
Definition: cddefines.h:127
const char * StandardEnergyUnit(void) const
Definition: parser.cpp:301
long getpos()
Definition: parser.h:559
float sys_float
Definition: cddefines.h:130
bool last(void) const
Definition: parser.cpp:201
void ParseIonPar(Parser &p, char chType)
Definition: parse_ionpar.cpp:20
void parse_save_colden(Parser &p, ostringstream &chHeader)
Definition: parser.h:34
void p_replaceSep()
Definition: parser.h:383
void p_pos(size_t p)
Definition: parser.h:361
DataParser(const string &name, eod_style es, access_scheme as=AS_DEFAULT)
Definition: parser.h:406
void ParseCMB(double z, long int *nqh)
Definition: parse_CMB.cpp:10
void p_close()
Definition: parser.cpp:1214
long i
Definition: parser.h:891
bool hasCommand(const string &s2)
Definition: parser.cpp:831
void ParseAbundances(Parser &p)
Definition: parse_abundances.cpp:18
void checkEOL()
Definition: parser.h:543
void skipTo(size_t p)
Definition: parser.h:514
void p_open(const string &name, eod_style es, access_scheme as)
have we passed beyond the EOF?
Definition: parser.cpp:1204
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:360
long min(int a, long b)
Definition: cddefines.h:766
void ParseMap(Parser &p)
Definition: parse_map.cpp:9
string m_card
Definition: parser.h:43
long int GetElem(void) const
Definition: parser.cpp:336
tokens
Definition: parser.h:34
Definition: parser.h:581
#define NULL
Definition: cddefines.h:115
const char * nWord(const char *chKey) const
Definition: parser.cpp:32
int nMatch1(const char *chKey) const
Definition: parser.h:135
string getFirstChunk(long i)
Definition: parser.cpp:569
void ParseCosmicRays(Parser &p)
Definition: parse_cosmic_rays.cpp:12
void getKeyword(string &str)
Definition: parser.h:506
bool isVar(void) const
Definition: parser.cpp:149
Definition: parser.h:311
long int m_len
Definition: parser.h:46
void ParseAbundancesNonSolar(Parser &p)
void ParseIlluminate(Parser &p)
Definition: parse_illuminate.cpp:11
void ParsePrtLineSum(Parser &p)
Definition: prt_linesum.cpp:42
void setDone()
Definition: parser.h:926
void ParseRatio(Parser &p)
Definition: parse_ratio.cpp:10
vector< pair< string, shared_ptr< Option > > > p
Definition: parser.h:924
Definition: parser.h:885
double getNumberCheckAlwaysLogLim(const char *chDesc, double flim)
Definition: parser.cpp:448
void ParseCompile(Parser &p)
Definition: parse_compile.cpp:14
void ParseConstant(Parser &p)
Definition: parse_constant.cpp:14
Definition: thirdparty.h:516
void help(FILE *fp) const
Definition: parser.cpp:309
void ParseInit(Parser &p)
Definition: parse_init.cpp:10
void close()
Definition: parser.h:417
bool l
Definition: parser.h:890
#define ASSERT(exp)
Definition: cddefines.h:637
void skipAfter(const string &s)
Definition: parser.h:521
KeyAction< V > MakeKeyAction(const char *keyword, const V &action)
Definition: parser.h:600
void ParsePrint(Parser &p)
Definition: parse_print.cpp:134
Definition: parser.h:34
bool getline()
Definition: parser.cpp:275
string getFirstChunkRaw(long i)
Definition: parser.cpp:584
void ParseNorm(Parser &p)
Definition: parse_norm.cpp:10
void ParseAbsMag(Parser &p)
Definition: parse_absmag.cpp:9
void ParseOptimize(Parser &p)
Definition: parse_optimize.cpp:30
Definition: parser.h:606
KeyAction(const char *keyword, const V &action)
Definition: parser.h:585
void ParseAge(Parser &p)
Definition: parse_age.cpp:38
NORETURN void Error(const char *msg) const
Definition: parser.cpp:248
bool GetParam(const char *chKey, double *val)
Definition: parser.h:167
Definition: parser.h:313
void ParseIonParI(Parser &p)
Definition: parse_ionpar.cpp:11
string m_getCommandToken() const
Definition: parser.cpp:892
bool getQuoteOptional(string &str)
Definition: parser.h:482
Definition: parser.h:887
double getNumberCheckAlwaysLog(const char *chDesc)
Definition: parser.cpp:442
Option(const string &val, enum Quoted q)
Definition: parser.h:910
void checkMagic(long i0)
Definition: parser.cpp:1286
Parser(const CloudyCommand *commands)
Definition: parser.h:60
const CloudyCommand *const m_Commands
Definition: parser.h:49
void ParseInitFile(const string &chName)
Definition: parse_init.cpp:47
double getNumberDefault(const char *chDesc, double fdef)
Definition: parser.cpp:416
char current(void) const
Definition: parser.h:87
void ParseGrid(Parser &p)
Definition: parse_grid.cpp:10
bool p_lgEOF
stream for reading current line
Definition: parser.h:320
bool lgEOL(void) const
Definition: parser.h:125
string value
Definition: parser.h:36
bool getKeywordOptional(string &str)
Definition: parser.h:499
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1325
DataParser()
Definition: parser.h:401
Definition: depth_table.h:7
NORETURN void CommandError(void) const
Definition: parser.cpp:259
bool p_isComment() const
Definition: parser.h:327
void getPairs(vector< double > &a, vector< double > &b)
Definition: parser.cpp:931
void ParseGlobule(Parser &p)
Definition: parse_globule.cpp:11
enum tokens toktype
Definition: parser.h:35
void ParseSet(Parser &p)
Definition: parse_set.cpp:38
void ParseMetal(Parser &p)
Definition: parse_metal.cpp:239
const char *const m_keyword
Definition: parser.h:582
void ParseDont(Parser &p)
Definition: parse_dont.cpp:28
char current_raw() const
Definition: parser.cpp:41
Definition: parser.h:920
int PrintLine(FILE *fp) const
Definition: parser.h:220
bool isOpen() const
Definition: parser.h:422
void p_getQuoteOptional(string &str)
Definition: parser.cpp:1257
void ParseBlackbody(Parser &p)
Definition: parse_blackbody.cpp:11
string p_line
what are the allowed EOD markers?
Definition: parser.h:317
void open(const string &name, eod_style es, access_scheme as=AS_DEFAULT)
Definition: parser.h:411
std::string getVarName(void)
Definition: parser.cpp:153
void caps(char *chCard)
Definition: service.cpp:299
enum Option::Opts opttype
bool getline()
Definition: parser.cpp:1342
void ParseBackgrd(Parser &p)
Definition: parse_backgrd.cpp:10
bool m_lgEOF
Definition: parser.h:54
void ParseF_nu(Parser &p, const char *chType, bool lgNU2)
Definition: parse_f_nu.cpp:9
Definition: parser.h:32
fstream p_io
the name of the data file
Definition: parser.h:315
void readLaw(DepthTable &table)
Definition: parser.cpp:1139
bool GetRange(const char *chKey, double *val1, double *val2)
Definition: parser.h:176
UnitConverter(double unit)
Definition: parser.h:610
string m_card_raw
Definition: parser.h:44
void ParseCrashDo(Parser &p)
Definition: parse_crashdo.cpp:51
void ParseFluc(Parser &p)
Definition: parse_fluc.cpp:9
void doSetVar(void)
Definition: parser.cpp:166
double getNumberDefaultNegImplLog(const char *chDesc, double fdef)
Definition: parser.cpp:470
double getWaveOpt()
Definition: parser.cpp:371
std::map< string, double > m_symtab
Definition: parser.h:50
void ParseSphere(Parser &p)
Definition: parse_sphere.cpp:9
const char * key(void) const
Definition: parser.h:588
std::map< string, size_t > m_uniqueLen
Definition: parser.h:51
V m_action
Definition: parser.h:583
void ParseDLaw(Parser &p)
Definition: parse_dlaw.cpp:10
bool p_isSeparator(char c)
Definition: parser.h:378
void ParseTLaw(Parser &p)
Definition: parse_tlaw.cpp:13
void ParseTrace(Parser &p)
Definition: parse_trace.cpp:11
string m_card_comment
Definition: parser.h:45
bool isComment(void) const
Definition: parser.cpp:145
bool p_blankLine() const
Definition: parser.h:340
void p_newlineProcess()
Definition: parser.cpp:1229
double r
Definition: parser.h:892
void ParseCoronal(Parser &p)
Definition: parse_coronal.cpp:14
void ParseInterp(Parser &p)
Definition: parse_interp.cpp:11
Definition: parser.h:888
double getNumberCheck(const char *chDesc)
Definition: parser.cpp:407
void ParseStop(Parser &p)
Definition: parse_stop.cpp:17