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