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 /*ParsePlot parse the plot command */ 00004 /*ParsePlotRangeOption parse range from plot command */ 00005 #include "cddefines.h" 00006 #include "plot.h" 00007 #include "rfield.h" 00008 #include "parse.h" 00009 00010 /*ParsePlotRangeOption parse range from plot command, located below */ 00011 STATIC void ParsePlotRangeOption(char*); 00012 00013 /*ParsePlotRangeContin parse range option for continuum on map command, located below */ 00014 STATIC void ParsePlotRangeContin(char*); 00015 00016 void ParsePlot(char *chCard ) 00017 { 00018 00019 DEBUG_ENTRY( "ParsePlot()" ); 00020 00021 /* total number of plots so far */ 00022 plotCom.nplot += 1; 00023 00024 /* plots are turned on */ 00025 plotCom.lgPlotON = true; 00026 00027 /* make sure we have not hit the limit, the dimension of variables in plot.h */ 00028 if( plotCom.nplot > NDPLOT ) 00029 { 00030 fprintf( ioQQQ, 00031 " Too many plots; the limit is%3ld This one ignored.\n", 00032 NDPLOT ); 00033 plotCom.nplot = NDPLOT; 00034 } 00035 00036 if( nMatch(" MAP",chCard) ) 00037 { 00038 /* option to make plot of heating - cooling map */ 00039 strcpy( plotCom.chPType[plotCom.nplot-1], " MAP" ); 00040 } 00041 00042 else if( nMatch("CONT",chCard) ) 00043 { 00044 /* option to make "raw" plot, in internal units */ 00045 if( nMatch(" RAW",chCard) ) 00046 { 00047 strcpy( plotCom.chPType[plotCom.nplot-1], "CRAW" ); 00048 /* option to make diffuse continuum plot */ 00049 } 00050 else if( nMatch("DIFF",chCard) ) 00051 { 00052 strcpy( plotCom.chPType[plotCom.nplot-1], "DIFF" ); 00053 /* this is emitted continuum */ 00054 } 00055 else if( nMatch("EMIT",chCard) ) 00056 { 00057 strcpy( plotCom.chPType[plotCom.nplot-1], "EMIT" ); 00058 /* this is outward and attenuated continuum */ 00059 } 00060 else if( nMatch("OUTW",chCard) ) 00061 { 00062 strcpy( plotCom.chPType[plotCom.nplot-1], "OUTW" ); 00063 /* this is reflected continuum */ 00064 } 00065 else if( nMatch("REFL",chCard) ) 00066 { 00067 strcpy( plotCom.chPType[plotCom.nplot-1], "REFL" ); 00068 /* this is continuum in photons */ 00069 } 00070 else if( nMatch("PHOT",chCard) ) 00071 { 00072 strcpy( plotCom.chPType[plotCom.nplot-1], "CPHT" ); 00073 } 00074 else 00075 { 00076 strcpy( plotCom.chPType[plotCom.nplot-1], "CONT" ); 00077 } 00078 } 00079 00080 else if( nMatch("OPAC",chCard) ) 00081 { 00082 if( nMatch("ABSO",chCard) ) 00083 { 00084 /* plot absorption opacity */ 00085 strcpy( plotCom.chPType[plotCom.nplot-1], "OPAA" ); 00086 } 00087 else if( nMatch("SCAT",chCard) ) 00088 { 00089 /* plot scattering opacity */ 00090 strcpy( plotCom.chPType[plotCom.nplot-1], "OPAS" ); 00091 } 00092 else if( nMatch("TOTA",chCard) ) 00093 { 00094 /* plot total opacity */ 00095 strcpy( plotCom.chPType[plotCom.nplot-1], "OPAT" ); 00096 } 00097 else 00098 { 00099 /* plot total opacity for default */ 00100 strcpy( plotCom.chPType[plotCom.nplot-1], "OPAT" ); 00101 } 00102 } 00103 else 00104 { 00105 fprintf( ioQQQ, " The second keyword on the PLOT command must be CONTINUUM, _MAP, or OPACITY.\n" ); 00106 cdEXIT(EXIT_FAILURE); 00107 } 00108 00109 /* option to turn on trace of plot logic */ 00110 if( nMatch("TRAC",chCard) ) 00111 { 00112 plotCom.lgPltTrace[plotCom.nplot-1] = true; 00113 } 00114 else 00115 { 00116 plotCom.lgPltTrace[plotCom.nplot-1] = false; 00117 } 00118 00119 /* option to set min and max x-axis */ 00120 if( strcmp(plotCom.chPType[plotCom.nplot-1]," MAP") == 0 ) 00121 { 00122 /* this will be map of cooling and heating vs temp */ 00123 ParsePlotRangeOption(chCard); 00124 } 00125 else 00126 { 00127 /* continuum map */ 00128 ParsePlotRangeContin(chCard); 00129 } 00130 00131 return; 00132 } 00133 00134 /*ParsePlotRangeOption parse range from plot command */ 00135 STATIC void ParsePlotRangeOption(char *chCard ) 00136 { 00137 bool lgEOL, 00138 lgLogOn; 00139 long int i; 00140 realnum a; 00141 00142 DEBUG_ENTRY( "ParsePlotRangeOption()" ); 00143 00144 i = 4; 00145 /* pltxmn is min for x axis of plot */ 00146 plotCom.pltxmn[plotCom.nplot-1] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00147 00148 if( !nMatch("RANG",chCard) ) 00149 { 00150 /* no lines were enterd, so use default temperature limits */ 00151 plotCom.pltxmn[plotCom.nplot-1] = 1.; 00152 plotCom.pltxmx[plotCom.nplot-1] = 9.; 00153 lgLogOn = true; 00154 } 00155 else if( lgEOL ) 00156 { 00157 /* no lines were enterd, so use default temperature limits */ 00158 plotCom.pltxmn[plotCom.nplot-1] = 1.; 00159 plotCom.pltxmx[plotCom.nplot-1] = 9.; 00160 lgLogOn = true; 00161 } 00162 else 00163 { 00164 /* number entered, now interprete it */ 00165 if( plotCom.pltxmn[plotCom.nplot-1] <= 10. ) 00166 { 00167 lgLogOn = true; 00168 } 00169 else 00170 { 00171 lgLogOn = false; 00172 } 00173 /* linear option for temperature */ 00174 if( nMatch("LINE",chCard) ) 00175 lgLogOn = false; 00176 /* lower temp was entered, now how about upper temp */ 00177 plotCom.pltxmx[plotCom.nplot-1] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00178 if( lgEOL ) 00179 { 00180 if( lgLogOn ) 00181 { 00182 plotCom.pltxmx[plotCom.nplot-1] = 9.; 00183 } 00184 else 00185 { 00186 plotCom.pltxmx[plotCom.nplot-1] = 1e9; 00187 } 00188 } 00189 else 00190 { 00191 /* second number was entered, check for sanity */ 00192 if( plotCom.pltxmx[plotCom.nplot-1] <= plotCom.pltxmn[plotCom.nplot-1] ) 00193 { 00194 fprintf( ioQQQ, 00195 " The second (maximum) temperature for the map is%10.2e, but this is less than the first (minimum) temperature,%10.2e\n", 00196 plotCom.pltxmx[plotCom.nplot-1], plotCom.pltxmn[plotCom.nplot-1] ); 00197 fprintf( ioQQQ, " HELP! I am confused!!\n" ); 00198 cdEXIT(EXIT_FAILURE); 00199 } 00200 } 00201 } 00202 00203 /* now force to be log */ 00204 if( !lgLogOn ) 00205 { 00206 if( plotCom.pltxmx[plotCom.nplot-1] <= 0. || plotCom.pltxmn[plotCom.nplot-1] <= 00207 0. ) 00208 { 00209 fprintf( ioQQQ, 00210 " Limits for temperature are negative. This is impossible. Sorry.\n" ); 00211 cdEXIT(EXIT_FAILURE); 00212 } 00213 plotCom.pltxmx[plotCom.nplot-1] = (realnum)log10(plotCom.pltxmx[plotCom.nplot-1]); 00214 plotCom.pltxmn[plotCom.nplot-1] = (realnum)log10(plotCom.pltxmn[plotCom.nplot-1]); 00215 } 00216 00217 /* check that min is less than max */ 00218 if( plotCom.pltxmn[plotCom.nplot-1] == plotCom.pltxmx[plotCom.nplot-1] ) 00219 { 00220 fprintf( ioQQQ, " Upper and lower plot boundaries are equal.\n" ); 00221 cdEXIT(EXIT_FAILURE); 00222 } 00223 else if( plotCom.pltxmn[plotCom.nplot-1] > plotCom.pltxmx[plotCom.nplot-1] ) 00224 { 00225 a = plotCom.pltxmx[plotCom.nplot-1]; 00226 plotCom.pltxmx[plotCom.nplot-1] = plotCom.pltxmn[plotCom.nplot-1]; 00227 plotCom.pltxmn[plotCom.nplot-1] = a; 00228 } 00229 00230 return; 00231 } 00232 00233 /*ParsePlotRangeContin set range for map to parse range option on map command */ 00234 STATIC void ParsePlotRangeContin(char *chCard ) 00235 { 00236 bool lgEOL, 00237 lgLogOn; 00238 long int i; 00239 realnum a; 00240 00241 DEBUG_ENTRY( "ParsePlotRangeContin()" ); 00242 00243 i = 4; 00244 plotCom.pltxmn[plotCom.nplot-1] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00245 00246 if( !nMatch("RANG",chCard) ) 00247 { 00248 /* no numbers on line, just set default limits to energy array */ 00249 plotCom.pltxmn[plotCom.nplot-1] = (realnum)log10(rfield.emm); 00250 plotCom.pltxmx[plotCom.nplot-1] = (realnum)log10(rfield.egamry); 00251 lgLogOn = true; 00252 } 00253 else if( lgEOL ) 00254 { 00255 /* no numbers on line, just set default limits to energy array */ 00256 plotCom.pltxmn[plotCom.nplot-1] = (realnum)log10(rfield.emm); 00257 plotCom.pltxmx[plotCom.nplot-1] = (realnum)log10(rfield.egamry); 00258 lgLogOn = true; 00259 } 00260 else 00261 { 00262 /* lower limit entered, now interprete it */ 00263 if( plotCom.pltxmn[plotCom.nplot-1] < 0. ) 00264 { 00265 lgLogOn = true; 00266 } 00267 else if( plotCom.pltxmn[plotCom.nplot-1] == 0.0 ) 00268 { 00269 /* option for first number to be zero, lower edge of array */ 00270 lgLogOn = false; 00271 plotCom.pltxmn[plotCom.nplot-1] = rfield.emm; 00272 } 00273 else 00274 { 00275 /* a positive number was entered */ 00276 lgLogOn = false; 00277 } 00278 00279 /* now look at upper limit */ 00280 plotCom.pltxmx[plotCom.nplot-1] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00281 if( lgEOL || plotCom.pltxmx[plotCom.nplot-1] == 0.0 ) 00282 { 00283 /* option for second number to be omitted or zero */ 00284 if( lgLogOn ) 00285 { 00286 plotCom.pltxmx[plotCom.nplot-1] = (realnum)log10(rfield.egamry); 00287 } 00288 else 00289 { 00290 plotCom.pltxmx[plotCom.nplot-1] = rfield.egamry; 00291 } 00292 } 00293 } 00294 00295 /* now force to be log */ 00296 if( !lgLogOn ) 00297 { 00298 plotCom.pltxmx[plotCom.nplot-1] = (realnum)log10(plotCom.pltxmx[plotCom.nplot-1]); 00299 plotCom.pltxmn[plotCom.nplot-1] = (realnum)log10(plotCom.pltxmn[plotCom.nplot-1]); 00300 } 00301 00302 /* check that min is less than max */ 00303 if( plotCom.pltxmn[plotCom.nplot-1] == plotCom.pltxmx[plotCom.nplot-1] ) 00304 { 00305 fprintf( ioQQQ, " Upper and lower plot boundaries are equal.\n" ); 00306 cdEXIT(EXIT_FAILURE); 00307 } 00308 else if( plotCom.pltxmn[plotCom.nplot-1] > plotCom.pltxmx[plotCom.nplot-1] ) 00309 { 00310 a = plotCom.pltxmx[plotCom.nplot-1]; 00311 plotCom.pltxmx[plotCom.nplot-1] = plotCom.pltxmn[plotCom.nplot-1]; 00312 plotCom.pltxmn[plotCom.nplot-1] = a; 00313 } 00314 00315 return; 00316 }