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 /*PrtLineSum parse print line sum command to enter set of lines into sum */ 00004 #include "cddefines.h" 00005 #include "cddrive.h" 00006 #include "radius.h" 00007 #include "lines.h" 00008 #include "input.h" 00009 /* this is the limit to the number of lines we can save */ 00010 #define NRDSUM 300L 00011 #include "prt.h" 00012 00013 double PrtLineSum( 00014 /* the job to do, either " SUM" or "READ" */ 00015 const char *chDo) 00016 { 00017 char chCCap[INPUT_LINE_LENGTH], 00018 chCard[INPUT_LINE_LENGTH]; 00019 00020 /*static char chSMLab[NRDSUM][5];*/ 00021 static char **chSMLab; 00022 bool lgEND, 00023 lgEOF, 00024 lgEOL; 00025 long int i; 00026 static long int *ipLine; 00027 00028 /* remember whether we have been called before */ 00029 static bool lgFirst=true; 00030 00031 /*static long int lamsm[NRDSUM], */ 00032 static long nlsum; 00033 static realnum *wavelength; 00034 00035 double absint, 00036 relint , 00037 sum=-1.; 00038 00039 DEBUG_ENTRY( "PrtLineSum()" ); 00040 00041 if( strcmp(chDo,"READ") == 0 ) 00042 { 00043 # if 0 00044 if( !lgFirst ) 00045 { 00046 /* error - more than one read in input stream */ 00047 fprintf(ioQQQ," more than one print line sum has appeared - only first one is used.\n"); 00048 fprintf(ioQQQ," Sorry.\n"); 00049 cdEXIT(EXIT_FAILURE); 00050 } 00051 else 00052 # endif 00053 /* >>chng 03 jan 23, if not first call, do not allocate space, 00054 * had aborted, which was bad in optized runs, or in a grid. 00055 * Bug caught by Melekh Bohdan */ 00056 if( lgFirst ) 00057 { 00058 /* do not malloc space again */ 00059 lgFirst = false; 00060 wavelength = ((realnum *)MALLOC( sizeof(realnum )*NRDSUM )); 00061 00062 /* create space for the array of array indices for lines*/ 00063 ipLine = ((long int *)MALLOC(NRDSUM*sizeof(long))); 00064 00065 /* create space for the array of labels*/ 00066 chSMLab = ((char **)MALLOC(NRDSUM*sizeof(char *))); 00067 00068 for( i=0; i<NRDSUM; ++i ) 00069 { 00070 chSMLab[i] = ((char *)MALLOC(5*sizeof(char ))); 00071 } 00072 } 00073 00074 /* now read in lines */ 00075 nlsum = 0; 00076 lgEND = false; 00077 while( !lgEND ) 00078 { 00079 input_readarray(chCard,&lgEOF); 00080 if( lgEOF ) 00081 { 00082 fprintf( ioQQQ, " Hit EOF while reading line list; use END to end list.\n" ); 00083 cdEXIT(EXIT_FAILURE); 00084 } 00085 strcpy( chCCap, chCard ); 00086 caps(chCCap); 00087 00088 if( strncmp(chCCap , "END" , 3) != 0 ) 00089 { 00090 if( nlsum >= NRDSUM ) 00091 { 00092 fprintf( ioQQQ, 00093 " Too many lines have been entered; the limit is %li. Increase NRDSUM in PrtLineSum.\n", 00094 NRDSUM ); 00095 cdEXIT(EXIT_FAILURE); 00096 } 00097 00098 /* order on line is label (col 1-4), wavelength */ 00099 strncpy( chSMLab[nlsum], chCCap , 4 ); 00100 chSMLab[nlsum][4] = 0; 00101 i = 5; 00102 wavelength[nlsum] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00103 /* check for optional micron or cm units, else interpret as Angstroms */ 00104 if( input.chCARDCAPS[i-1] == 'M' ) 00105 { 00106 /* microns */ 00107 wavelength[nlsum] *= 1e4; 00108 } 00109 else if( input.chCARDCAPS[i-1] == 'C' ) 00110 { 00111 /* microns */ 00112 wavelength[nlsum] *= 1e8; 00113 } 00114 ++nlsum; 00115 } 00116 else 00117 { 00118 lgEND = true; 00119 } 00120 } 00121 } 00122 00123 else if( strcmp(chDo," SUM" ) == 0 ) 00124 { 00125 sum = 0.; 00126 /* this can be called during setup mode, in which case we do nothing */ 00127 if( LineSave.ipass <= 0 ) 00128 { 00129 return( sum ); 00130 } 00131 00132 if( nzone == 1 ) 00133 { 00134 for( i=0; i < nlsum; i++ ) 00135 { 00136 /* save the array index for each line */ 00137 if( (ipLine[i] = cdLine((char*)chSMLab[i],wavelength[i],&relint,&absint) ) <=0 ) 00138 { 00139 fprintf( ioQQQ, " PrtLineSum could not fine line %4.4s %5f\n", 00140 chSMLab[i], wavelength[i] ); 00141 cdEXIT(EXIT_FAILURE); 00142 } 00143 } 00144 } 00145 00146 /* now sum the line */ 00147 for( i=0; i < nlsum; i++ ) 00148 { 00149 /* this version of chLine uses index, does not search*/ 00150 cdLine_ip(ipLine[i],&relint,&absint); 00151 absint = pow(10.,absint - radius.Conv2PrtInten); 00152 sum += absint; 00153 } 00154 } 00155 00156 else 00157 { 00158 fprintf( ioQQQ, " unrecognized key for PrtLineSum=%s\n", 00159 chDo ); 00160 cdEXIT(EXIT_FAILURE); 00161 } 00162 return( sum ); 00163 }