cloudy
trunk
source
prt_linesum.cpp
Go to the documentation of this file.
1
/* This file is part of Cloudy and is copyright (C)1978-2013 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 "
input.h
"
9
#include "
parser.h
"
10
/* this is the limit to the number of lines we can save */
11
#define NRDSUM 300L
12
#include "
prt.h
"
13
14
static
char
**
chSMLab
;
15
static
long
int
*
ipLine
;
16
static
bool
lgFirst
=
true
;
17
static
long
nlsum
;
18
static
realnum
*
wavelength
;
19
20
void
ParsePrtLineSum
(
Parser
&p)
21
{
22
/*static char chSMLab[NRDSUM][5];*/
23
bool
lgEND;
24
long
int
i;
25
26
/* remember whether we have been called before */
27
28
DEBUG_ENTRY
(
"ParsePrtLineSum()"
);
29
30
# if 0
31
if
( !
lgFirst
)
32
{
33
/* error - more than one read in input stream */
34
fprintf(
ioQQQ
,
" more than one print line sum has appeared - only first one is used.\n"
);
35
fprintf(
ioQQQ
,
" Sorry.\n"
);
36
cdEXIT
(
EXIT_FAILURE
);
37
}
38
else
39
# endif
40
/* >>chng 03 jan 23, if not first call, do not allocate space,
41
* had aborted, which was bad in optized runs, or in a grid.
42
* Bug caught by Melekh Bohdan */
43
if
(
lgFirst
)
44
{
45
/* do not malloc space again */
46
lgFirst
=
false
;
47
wavelength
= ((
realnum
*)
MALLOC
(
sizeof
(
realnum
)*
NRDSUM
));
48
49
/* create space for the array of array indices for lines*/
50
ipLine
= ((
long
int
*)
MALLOC
(
NRDSUM
*
sizeof
(
long
)));
51
52
/* create space for the array of labels*/
53
chSMLab
= ((
char
**)
MALLOC
(
NRDSUM
*
sizeof
(
char
*)));
54
55
for
( i=0; i<
NRDSUM
; ++i )
56
{
57
chSMLab
[i] = ((
char
*)
MALLOC
(5*
sizeof
(
char
)));
58
}
59
}
60
61
/* now read in lines */
62
nlsum
= 0;
63
lgEND =
false
;
64
while
( !lgEND )
65
{
66
p.
getline
();
67
if
( p.
m_lgEOF
)
68
{
69
fprintf(
ioQQQ
,
" Hit EOF while reading line list; use END to end list.\n"
);
70
cdEXIT
(
EXIT_FAILURE
);
71
}
72
73
if
( p.
strcmp
(
"END"
) != 0 )
74
{
75
if
(
nlsum
>=
NRDSUM
)
76
{
77
fprintf(
ioQQQ
,
78
" Too many lines have been entered; the limit is %li. Increase NRDSUM in PrtLineSum.\n"
,
79
NRDSUM
);
80
cdEXIT
(
EXIT_FAILURE
);
81
}
82
83
/* order on line is label (col 1-4), wavelength */
84
strncpy(
chSMLab
[
nlsum
], p.
getCommand
(4).c_str() , 4 );
85
chSMLab
[
nlsum
][4] = 0;
86
wavelength
[
nlsum
] = (
realnum
)p.
getWaveOpt
();
87
++
nlsum
;
88
}
89
else
90
{
91
lgEND =
true
;
92
}
93
}
94
}
95
double
PrtLineSum
(
void
)
96
{
97
long
int
i;
98
99
/* remember whether we have been called before */
100
101
double
absint,
102
relint ,
103
sum=-1.;
104
105
DEBUG_ENTRY
(
"PrtLineSum()"
);
106
107
sum = 0.;
108
/* this can be called during setup mode, in which case we do nothing */
109
if
(
LineSave
.
ipass
<= 0 )
110
{
111
return
sum;
112
}
113
114
if
(
nzone
== 1 )
115
{
116
for
( i=0; i <
nlsum
; i++ )
117
{
118
/* save the array index for each line */
119
if
( (
ipLine
[i] =
cdLine
((
char
*)
chSMLab
[i],
wavelength
[i],&relint,&absint) ) <=0 )
120
{
121
fprintf(
ioQQQ
,
" PrtLineSum could not fine line %4.4s %5f\n"
,
122
chSMLab
[i],
wavelength
[i] );
123
cdEXIT
(
EXIT_FAILURE
);
124
}
125
}
126
}
127
128
/* now sum the line */
129
for
( i=0; i <
nlsum
; i++ )
130
{
131
/* this version of chLine uses index, does not search*/
132
cdLine_ip
(
ipLine
[i],&relint,&absint);
133
absint = pow(10.,absint -
radius
.
Conv2PrtInten
);
134
sum += absint;
135
}
136
return
sum;
137
}
138
lines.h
ioQQQ
FILE * ioQQQ
Definition:
cddefines.cpp:7
PrtLineSum
double PrtLineSum(void)
Definition:
prt_linesum.cpp:95
t_radius::Conv2PrtInten
double Conv2PrtInten
Definition:
radius.h:147
realnum
float realnum
Definition:
cddefines.h:103
wavelength
static realnum * wavelength
Definition:
prt_linesum.cpp:18
Parser::m_lgEOF
bool m_lgEOF
Definition:
parser.h:42
cddrive.h
nzone
long int nzone
Definition:
cddefines.cpp:14
LineSave
t_LineSave LineSave
Definition:
lines.cpp:5
radius
t_radius radius
Definition:
radius.cpp:5
EXIT_FAILURE
#define EXIT_FAILURE
Definition:
cddefines.h:140
ipLine
static long int * ipLine
Definition:
prt_linesum.cpp:15
NRDSUM
#define NRDSUM
Definition:
prt_linesum.cpp:11
Parser
Definition:
parser.h:31
Parser::getline
bool getline(void)
Definition:
parser.cpp:164
cddefines.h
t_LineSave::ipass
long int ipass
Definition:
lines.h:75
radius.h
MALLOC
#define MALLOC(exp)
Definition:
cddefines.h:501
ParsePrtLineSum
void ParsePrtLineSum(Parser &p)
Definition:
prt_linesum.cpp:20
lgFirst
static bool lgFirst
Definition:
prt_linesum.cpp:16
chSMLab
static char ** chSMLab
Definition:
prt_linesum.cpp:14
cdEXIT
#define cdEXIT(FAIL)
Definition:
cddefines.h:434
cdLine
long int cdLine(const char *chLabel, realnum wavelength, double *relint, double *absint)
Definition:
cddrive.cpp:1228
prt.h
nlsum
static long nlsum
Definition:
prt_linesum.cpp:17
parser.h
cdLine_ip
void cdLine_ip(long int ipLine, double *relint, double *absint)
Definition:
cddrive.cpp:1414
Parser::strcmp
int strcmp(const char *s2)
Definition:
parser.h:177
input.h
Parser::getCommand
string getCommand(long i)
Definition:
parser.h:215
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition:
cddefines.h:684
Parser::getWaveOpt
double getWaveOpt()
Definition:
parser.cpp:244
Generated by
1.8.17