cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
prt_linesum.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 /*PrtLineSum parse print line sum command to enter set of lines into sum */
4 #include "cddefines.h"
5 #include "cddrive.h"
6 #include "radius.h"
7 #include "lines.h"
8 #include "parser.h"
9 /* this is the limit to the number of lines we can save */
10 #define NRDSUM 300L
11 #include "prt.h"
12 
13 static string strSMLab[NRDSUM];
14 static long int *ipLine;
15 static long nlsum;
17 
19 {
20  static bool lgFirst=true;
21 
22  /* remember whether we have been called before */
23 
24  DEBUG_ENTRY( "ParsePrtLineSum()" );
25 
26  /* >>chng 03 jan 23, if not first call, do not allocate space,
27  * had aborted, which was bad in optized runs, or in a grid.
28  * Bug caught by Melekh Bohdan */
29  if( lgFirst )
30  {
31  /* do not malloc space again */
32  lgFirst = false;
33  wavelength = ((realnum *)MALLOC( sizeof(realnum )*NRDSUM ));
34 
35  /* create space for the array of array indices for lines*/
36  ipLine = ((long int *)MALLOC(NRDSUM*sizeof(long)));
37  }
38 
39  /* now read in lines */
40  nlsum = 0;
41  bool lgEND = false;
42  while( !lgEND )
43  {
44  p.getline();
45  if( p.m_lgEOF )
46  {
47  fprintf( ioQQQ, " Hit EOF while reading line list; use END to end list.\n" );
49  }
50 
51  if( ! p.hasCommand("END" ) )
52  {
53  if( nlsum >= NRDSUM )
54  {
55  fprintf( ioQQQ,
56  " Too many lines have been entered; the limit is %li. Increase NRDSUM in PrtLineSum.\n",
57  NRDSUM );
59  }
60 
61  LineID line = p.getLineID();
62  if( !p.lgReachedEnd() )
63  {
64  fprintf( ioQQQ, "ParsePrtLineSum: found junk at end of input line:\n" );
65  p.showLocation();
67  }
68  strSMLab[nlsum] = line.chLabel;
69  wavelength[nlsum] = line.wave;
70  ++nlsum;
71  }
72  else
73  {
74  lgEND = true;
75  }
76  }
77 }
78 double PrtLineSum(void)
79 {
80  long int i;
81 
82  /* remember whether we have been called before */
83 
84  double absint,
85  relint ,
86  sum=-1.;
87 
88  DEBUG_ENTRY( "PrtLineSum()" );
89 
90  sum = 0.;
91  /* this can be called during setup mode, in which case we do nothing */
92  if( LineSave.ipass <= 0 )
93  {
94  return sum;
95  }
96 
97  if( nzone == 1 )
98  {
99  bool lgFail = false;
100  for( i=0; i < nlsum; i++ )
101  {
102  /* save the array index for each line */
103  if(( ipLine[i] = LineSave.findline( strSMLab[i].c_str(), wavelength[i]) ) <= 0 )
104  {
105  fprintf( ioQQQ, " PrtLineSum could not find line " );
106  prt_line_err( ioQQQ, strSMLab[i].c_str(), wavelength[i] );
107  lgFail = true;
108  }
109  }
110  if( lgFail )
112  }
113 
114  /* now sum the line */
115  for( i=0; i < nlsum; i++ )
116  {
117  /* this version of chLine uses index, does not search*/
118  cdLine_ip(ipLine[i],&relint,&absint);
119  absint /= radius.Conv2PrtInten;
120  sum += absint;
121  }
122  return sum;
123 }
124 
void cdLine_ip(long int ipLine, double *relint, double *absint)
Definition: cddrive.cpp:1110
bool hasCommand(const char *s2)
Definition: parser.cpp:746
realnum wave
Definition: lines.h:18
static long nlsum
Definition: prt_linesum.cpp:15
long findline(const char *chLabel, realnum wavelength)
Definition: lines.cpp:294
bool lgReachedEnd()
Definition: parser.cpp:109
t_LineSave LineSave
Definition: lines.cpp:10
Definition: lines.h:14
FILE * ioQQQ
Definition: cddefines.cpp:7
string chLabel
Definition: lines.h:17
long int nzone
Definition: cddefines.cpp:14
Definition: parser.h:43
void prt_line_err(FILE *ioOUT, const char *label, realnum wvlng)
Definition: prt.cpp:161
#define MALLOC(exp)
Definition: cddefines.h:554
LineID getLineID()
Definition: parser.cpp:569
#define NRDSUM
Definition: prt_linesum.cpp:10
static realnum * wavelength
Definition: prt_linesum.cpp:16
void showLocation(FILE *io=ioQQQ) const
Definition: parser.cpp:115
float realnum
Definition: cddefines.h:124
#define EXIT_FAILURE
Definition: cddefines.h:168
#define cdEXIT(FAIL)
Definition: cddefines.h:482
t_radius radius
Definition: radius.cpp:5
void ParsePrtLineSum(Parser &p)
Definition: prt_linesum.cpp:18
double Conv2PrtInten
Definition: radius.h:153
bool getline()
Definition: parser.cpp:273
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
static string strSMLab[NRDSUM]
Definition: prt_linesum.cpp:13
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
double PrtLineSum(void)
Definition: prt_linesum.cpp:78
bool m_lgEOF
Definition: parser.h:55
static long int * ipLine
Definition: prt_linesum.cpp:14
long int ipass
Definition: lines.h:96