cloudy  trunk
 All Data Structures 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-2008 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 /* this is the limit to the number of lines we can save */
10 #define NRDSUM 300L
11 #include "prt.h"
12 
13 double PrtLineSum(
14  /* the job to do, either " SUM" or "READ" */
15  const char *chDo)
16 {
17  char chCCap[INPUT_LINE_LENGTH],
18  chCard[INPUT_LINE_LENGTH];
19 
20  /*static char chSMLab[NRDSUM][5];*/
21  static char **chSMLab;
22  bool lgEND,
23  lgEOF,
24  lgEOL;
25  long int i;
26  static long int *ipLine;
27 
28  /* remember whether we have been called before */
29  static bool lgFirst=true;
30 
31  /*static long int lamsm[NRDSUM], */
32  static long nlsum;
33  static realnum *wavelength;
34 
35  double absint,
36  relint ,
37  sum=-1.;
38 
39  DEBUG_ENTRY( "PrtLineSum()" );
40 
41  if( strcmp(chDo,"READ") == 0 )
42  {
43 # if 0
44  if( !lgFirst )
45  {
46  /* error - more than one read in input stream */
47  fprintf(ioQQQ," more than one print line sum has appeared - only first one is used.\n");
48  fprintf(ioQQQ," Sorry.\n");
49  cdEXIT(EXIT_FAILURE);
50  }
51  else
52 # endif
53  /* >>chng 03 jan 23, if not first call, do not allocate space,
54  * had aborted, which was bad in optized runs, or in a grid.
55  * Bug caught by Melekh Bohdan */
56  if( lgFirst )
57  {
58  /* do not malloc space again */
59  lgFirst = false;
60  wavelength = ((realnum *)MALLOC( sizeof(realnum )*NRDSUM ));
61 
62  /* create space for the array of array indices for lines*/
63  ipLine = ((long int *)MALLOC(NRDSUM*sizeof(long)));
64 
65  /* create space for the array of labels*/
66  chSMLab = ((char **)MALLOC(NRDSUM*sizeof(char *)));
67 
68  for( i=0; i<NRDSUM; ++i )
69  {
70  chSMLab[i] = ((char *)MALLOC(5*sizeof(char )));
71  }
72  }
73 
74  /* now read in lines */
75  nlsum = 0;
76  lgEND = false;
77  while( !lgEND )
78  {
79  input_readarray(chCard,&lgEOF);
80  if( lgEOF )
81  {
82  fprintf( ioQQQ, " Hit EOF while reading line list; use END to end list.\n" );
83  cdEXIT(EXIT_FAILURE);
84  }
85  strcpy( chCCap, chCard );
86  caps(chCCap);
87 
88  if( strncmp(chCCap , "END" , 3) != 0 )
89  {
90  if( nlsum >= NRDSUM )
91  {
92  fprintf( ioQQQ,
93  " Too many lines have been entered; the limit is %li. Increase NRDSUM in PrtLineSum.\n",
94  NRDSUM );
95  cdEXIT(EXIT_FAILURE);
96  }
97 
98  /* order on line is label (col 1-4), wavelength */
99  strncpy( chSMLab[nlsum], chCCap , 4 );
100  chSMLab[nlsum][4] = 0;
101  i = 5;
102  wavelength[nlsum] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
103  /* check for optional micron or cm units, else interpret as Angstroms */
104  if( input.chCARDCAPS[i-1] == 'M' )
105  {
106  /* microns */
107  wavelength[nlsum] *= 1e4;
108  }
109  else if( input.chCARDCAPS[i-1] == 'C' )
110  {
111  /* microns */
112  wavelength[nlsum] *= 1e8;
113  }
114  ++nlsum;
115  }
116  else
117  {
118  lgEND = true;
119  }
120  }
121  }
122 
123  else if( strcmp(chDo," SUM" ) == 0 )
124  {
125  sum = 0.;
126  /* this can be called during setup mode, in which case we do nothing */
127  if( LineSave.ipass <= 0 )
128  {
129  return( sum );
130  }
131 
132  if( nzone == 1 )
133  {
134  for( i=0; i < nlsum; i++ )
135  {
136  /* save the array index for each line */
137  if( (ipLine[i] = cdLine((char*)chSMLab[i],wavelength[i],&relint,&absint) ) <=0 )
138  {
139  fprintf( ioQQQ, " PrtLineSum could not fine line %4.4s %5f\n",
140  chSMLab[i], wavelength[i] );
141  cdEXIT(EXIT_FAILURE);
142  }
143  }
144  }
145 
146  /* now sum the line */
147  for( i=0; i < nlsum; i++ )
148  {
149  /* this version of chLine uses index, does not search*/
150  cdLine_ip(ipLine[i],&relint,&absint);
151  absint = pow(10.,absint - radius.Conv2PrtInten);
152  sum += absint;
153  }
154  }
155 
156  else
157  {
158  fprintf( ioQQQ, " unrecognized key for PrtLineSum=%s\n",
159  chDo );
160  cdEXIT(EXIT_FAILURE);
161  }
162  return( sum );
163 }

Generated for cloudy by doxygen 1.8.4