cloudy
trunk
|
00001 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and 00002 * others. For conditions of distribution and use see copyright notice in license.txt */ 00003 /*coolpr stores coolants before block printed, when printing cooling agents */ 00004 #include "cddefines.h" 00005 #include "thermal.h" 00006 #include "cooling.h" 00007 #define NCOLSAV 100 00008 00009 void coolpr( 00010 FILE * io, 00011 /* the line label */ 00012 const char *chLabel, 00013 /* the line wavelength */ 00014 realnum lambda, 00015 /* the ratio of cooling to total, negative if a heat source */ 00016 double ratio, 00017 /* the job to do, one of "ZERO", "DOIT", or "DONE" */ 00018 const char *chJOB 00019 ) 00020 { 00021 static char chLabsv[NCOLSAV][NCOLNT_LAB_LEN+1]; 00022 00023 static char chSig[NCOLSAV]; 00024 00025 long int i, 00026 ipAr[NCOLSAV], 00027 j, 00028 limit; 00029 00030 static long int nCoolant = 0; 00031 static realnum sav[NCOLSAV]; 00032 00033 realnum SavMax, 00034 scratch[NCOLSAV]; 00035 00036 static realnum csav[NCOLSAV]; 00037 00038 DEBUG_ENTRY( "coolpr()" ); 00039 00040 /* routine is called with two flags, "ZERO" and "DONE" to 00041 * initialize and complete the printout. Any other label is 00042 * interpreted as a line label */ 00043 if( strcmp(chJOB,"ZERO") == 0 ) 00044 { 00045 /* nCoolant is the counter through the array of coolants, 00046 * zero it if new job to do */ 00047 nCoolant = 0; 00048 for( i=0; i<NCOLSAV; ++i ) 00049 { 00050 scratch[i] = FLT_MAX; 00051 ipAr[i] = LONG_MAX; 00052 } 00053 } 00054 00055 else if( strcmp(chJOB,"DOIT") == 0 ) 00056 { 00057 strcpy( chLabsv[nCoolant], chLabel ); 00058 00059 if( lambda < 10000. ) 00060 { 00061 sav[nCoolant] = lambda; 00062 } 00063 else 00064 { 00065 sav[nCoolant] = lambda/10000.f; 00066 } 00067 00068 csav[nCoolant] = (realnum)ratio; 00069 /* is this coolant really cooling (+) or a heat source? */ 00070 if( ratio < 0. ) 00071 { 00072 chSig[nCoolant] = 'n'; 00073 } 00074 else 00075 { 00076 chSig[nCoolant] = ' '; 00077 } 00078 00079 /* increment the counter, so this is the number actually in the stack */ 00080 ++nCoolant; 00081 00082 /* this is limit to how much we can save */ 00083 if( nCoolant >= NCOLSAV ) 00084 { 00085 fprintf( ioQQQ, " coolpr ran out of room, increase NCOLSAV.\n" ); 00086 ShowMe(); 00087 cdEXIT(EXIT_FAILURE); 00088 } 00089 } 00090 00091 else if( strcmp(chJOB,"DONE") == 0 ) 00092 { 00093 /* want to print sorted list of coolants sorted from strongest to faintest */ 00094 for( i=0; i < nCoolant; i++ ) 00095 { 00096 /* save abs val so we pick up both heating and cooling */ 00097 scratch[i] = (realnum)fabs(csav[i]); 00098 } 00099 00100 for( i=0; i < nCoolant; i++ ) 00101 { 00102 SavMax = 0.; 00103 /* following will be reset in following loop */ 00104 ipAr[i] = -LONG_MAX; 00105 00106 /* find largest of remaining coolants */ 00107 for( j=0; j < nCoolant; j++ ) 00108 { 00109 if( scratch[j] > SavMax ) 00110 { 00111 SavMax = scratch[j]; 00112 /* ipAr will point to coolant within saved stack */ 00113 ipAr[i] = j; 00114 } 00115 } 00116 00117 ASSERT( i >= 0 && i < NCOLSAV ); 00118 ASSERT( ipAr[i] >=0 && ipAr[i] < NCOLSAV ); 00119 /* set it to zero so we can look for next strongest */ 00120 scratch[ipAr[i]] = 0.; 00121 } 00122 00123 /* now print this stack in order or strength, seven across a line */ 00124 for( j=0; j < nCoolant; j += 7 ) 00125 { 00126 limit = MIN2(nCoolant,j+7); 00127 fprintf( io, " " ); 00128 for( i=j; i < limit; i++ ) 00129 { 00130 ASSERT( i < NCOLSAV ); 00131 00132 fprintf( io, 00133 " %s %.2f%c%6.3f", 00134 /* label for the coolant, like "C 4" */ 00135 chLabsv[ipAr[i]], 00136 /* wavelength */ 00137 sav[ipAr[i]], 00138 /* usually space, but n if negative coolant */ 00139 chSig[ipAr[i]], 00140 /* fraction of total cooling */ 00141 csav[ipAr[i]] ); 00142 } 00143 fprintf( io, " \n" ); 00144 } 00145 } 00146 00147 else 00148 { 00149 fprintf( ioQQQ, " coolpr called with insane job =%s=\n",chJOB ); 00150 ShowMe(); 00151 cdEXIT(EXIT_FAILURE); 00152 } 00153 return; 00154 }