cloudy trunk
Loading...
Searching...
No Matches
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
14static char **chSMLab;
15static long int *ipLine;
16static bool lgFirst=true;
17static long nlsum;
19
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");
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" );
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 );
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;
87 ++nlsum;
88 }
89 else
90 {
91 lgEND = true;
92 }
93 }
94}
95double 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] );
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
long int nzone
Definition cddefines.cpp:14
FILE * ioQQQ
Definition cddefines.cpp:7
#define MALLOC(exp)
Definition cddefines.h:501
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
float realnum
Definition cddefines.h:103
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
void cdLine_ip(long int ipLine, double *relint, double *absint)
Definition cddrive.cpp:1414
long int cdLine(const char *chLabel, realnum wavelength, double *relint, double *absint)
Definition cddrive.cpp:1228
bool getline(void)
Definition parser.cpp:164
double getWaveOpt()
Definition parser.cpp:244
int strcmp(const char *s2)
Definition parser.h:177
bool m_lgEOF
Definition parser.h:42
string getCommand(long i)
Definition parser.h:215
t_LineSave LineSave
Definition lines.cpp:5
static realnum * wavelength
static long nlsum
static bool lgFirst
static long int * ipLine
#define NRDSUM
static char ** chSMLab
void ParsePrtLineSum(Parser &p)
double PrtLineSum(void)
t_radius radius
Definition radius.cpp:5