cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cool_pr.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 /*coolpr stores coolants before block printed, when printing cooling agents */
4 #include "cddefines.h"
5 #include "thermal.h"
6 #include "cooling.h"
7 #define NCOLSAV 100
8 
9 void coolpr(
10  FILE * io,
11  /* the line label */
12  const char *chLabel,
13  /* the line wavelength */
14  realnum lambda,
15  /* the ratio of cooling to total, negative if a heat source */
16  double ratio,
17  /* the job to do, one of "ZERO", "DOIT", or "DONE" */
18  const char *chJOB
19  )
20 {
21  static char chLabsv[NCOLSAV][NCOLNT_LAB_LEN+1];
22 
23  static char chSig[NCOLSAV];
24 
25  long int i,
26  ipAr[NCOLSAV],
27  j,
28  limit;
29 
30  static long int nCoolant = 0;
31  static realnum sav[NCOLSAV];
32 
33  realnum SavMax,
34  scratch[NCOLSAV];
35 
36  static realnum csav[NCOLSAV];
37 
38  DEBUG_ENTRY( "coolpr()" );
39 
40  /* routine is called with two flags, "ZERO" and "DONE" to
41  * initialize and complete the printout. Any other label is
42  * interpreted as a line label */
43  if( strcmp(chJOB,"ZERO") == 0 )
44  {
45  /* nCoolant is the counter through the array of coolants,
46  * zero it if new job to do */
47  nCoolant = 0;
48  for( i=0; i<NCOLSAV; ++i )
49  {
50  scratch[i] = FLT_MAX;
51  ipAr[i] = LONG_MAX;
52  }
53  }
54 
55  else if( strcmp(chJOB,"DOIT") == 0 )
56  {
57  strcpy( chLabsv[nCoolant], chLabel );
58 
59  if( lambda < 10000. )
60  {
61  sav[nCoolant] = lambda;
62  }
63  else
64  {
65  sav[nCoolant] = lambda/10000.f;
66  }
67 
68  csav[nCoolant] = (realnum)ratio;
69  /* is this coolant really cooling (+) or a heat source? */
70  if( ratio < 0. )
71  {
72  chSig[nCoolant] = 'n';
73  }
74  else
75  {
76  chSig[nCoolant] = ' ';
77  }
78 
79  /* increment the counter, so this is the number actually in the stack */
80  ++nCoolant;
81 
82  /* this is limit to how much we can save */
83  if( nCoolant >= NCOLSAV )
84  {
85  fprintf( ioQQQ, " coolpr ran out of room, increase NCOLSAV.\n" );
86  ShowMe();
87  cdEXIT(EXIT_FAILURE);
88  }
89  }
90 
91  else if( strcmp(chJOB,"DONE") == 0 )
92  {
93  /* want to print sorted list of coolants sorted from strongest to faintest */
94  for( i=0; i < nCoolant; i++ )
95  {
96  /* save abs val so we pick up both heating and cooling */
97  scratch[i] = (realnum)fabs(csav[i]);
98  }
99 
100  for( i=0; i < nCoolant; i++ )
101  {
102  SavMax = 0.;
103  /* following will be reset in following loop */
104  ipAr[i] = -LONG_MAX;
105 
106  /* find largest of remaining coolants */
107  for( j=0; j < nCoolant; j++ )
108  {
109  if( scratch[j] > SavMax )
110  {
111  SavMax = scratch[j];
112  /* ipAr will point to coolant within saved stack */
113  ipAr[i] = j;
114  }
115  }
116 
117  ASSERT( i >= 0 && i < NCOLSAV );
118  ASSERT( ipAr[i] >=0 && ipAr[i] < NCOLSAV );
119  /* set it to zero so we can look for next strongest */
120  scratch[ipAr[i]] = 0.;
121  }
122 
123  /* now print this stack in order or strength, seven across a line */
124  for( j=0; j < nCoolant; j += 7 )
125  {
126  limit = MIN2(nCoolant,j+7);
127  fprintf( io, " " );
128  for( i=j; i < limit; i++ )
129  {
130  ASSERT( i < NCOLSAV );
131 
132  fprintf( io,
133  " %s %.2f%c%6.3f",
134  /* label for the coolant, like "C 4" */
135  chLabsv[ipAr[i]],
136  /* wavelength */
137  sav[ipAr[i]],
138  /* usually space, but n if negative coolant */
139  chSig[ipAr[i]],
140  /* fraction of total cooling */
141  csav[ipAr[i]] );
142  }
143  fprintf( io, " \n" );
144  }
145  }
146 
147  else
148  {
149  fprintf( ioQQQ, " coolpr called with insane job =%s=\n",chJOB );
150  ShowMe();
151  cdEXIT(EXIT_FAILURE);
152  }
153  return;
154 }

Generated for cloudy by doxygen 1.8.4