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-2017 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  strSMLab[nlsum] = line.chLabel;
63  wavelength[nlsum] = line.wave;
64  ++nlsum;
65  }
66  else
67  {
68  lgEND = true;
69  }
70  }
71 }
72 double PrtLineSum(void)
73 {
74  long int i;
75 
76  /* remember whether we have been called before */
77 
78  double absint,
79  relint ,
80  sum=-1.;
81 
82  DEBUG_ENTRY( "PrtLineSum()" );
83 
84  sum = 0.;
85  /* this can be called during setup mode, in which case we do nothing */
86  if( LineSave.ipass <= 0 )
87  {
88  return sum;
89  }
90 
91  if( nzone == 1 )
92  {
93  bool lgFail = false;
94  for( i=0; i < nlsum; i++ )
95  {
96  /* save the array index for each line */
97  if(( ipLine[i] = LineSave.findline( strSMLab[i].c_str(), wavelength[i]) ) <= 0 )
98  {
99  fprintf( ioQQQ, " PrtLineSum could not find line " );
100  prt_line_err( ioQQQ, strSMLab[i].c_str(), wavelength[i] );
101  lgFail = true;
102  }
103  }
104  if( lgFail )
106  }
107 
108  /* now sum the line */
109  for( i=0; i < nlsum; i++ )
110  {
111  /* this version of chLine uses index, does not search*/
112  cdLine_ip(ipLine[i],&relint,&absint);
113  absint /= radius.Conv2PrtInten;
114  sum += absint;
115  }
116  return sum;
117 }
118 
void cdLine_ip(long int ipLine, double *relint, double *absint)
Definition: cddrive.cpp:1112
bool hasCommand(const char *s2)
Definition: parser.cpp:705
realnum wave
Definition: lines.h:18
static long nlsum
Definition: prt_linesum.cpp:15
long findline(const char *chLabel, realnum wavelength)
Definition: lines.cpp:293
t_LineSave LineSave
Definition: lines.cpp:9
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:42
void prt_line_err(FILE *ioOUT, const char *label, realnum wvlng)
Definition: prt.cpp:161
#define MALLOC(exp)
Definition: cddefines.h:556
LineID getLineID()
Definition: parser.cpp:535
#define NRDSUM
Definition: prt_linesum.cpp:10
static realnum * wavelength
Definition: prt_linesum.cpp:16
float realnum
Definition: cddefines.h:124
#define EXIT_FAILURE
Definition: cddefines.h:168
#define cdEXIT(FAIL)
Definition: cddefines.h:484
t_radius radius
Definition: radius.cpp:5
void ParsePrtLineSum(Parser &p)
Definition: prt_linesum.cpp:18
double Conv2PrtInten
Definition: radius.h:152
bool getline()
Definition: parser.cpp:249
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:729
static string strSMLab[NRDSUM]
Definition: prt_linesum.cpp:13
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1217
double PrtLineSum(void)
Definition: prt_linesum.cpp:72
bool m_lgEOF
Definition: parser.h:53
static long int * ipLine
Definition: prt_linesum.cpp:14
long int ipass
Definition: lines.h:96