Show
Ignore:
Timestamp:
05/17/08 09:51:43 (8 months ago)
Author:
rjrw
Message:

Merged from trunk r2022:2078

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/newmole/source/cdspec.cpp

    r1780 r2079  
    318318         * 3    the reflected continuum, same units 
    319319         * 
    320          * 4    diffuse continuous emission outward direction 
    321          * 5    diffuse continuous emission, reflected 
    322          * 
    323          * 6    collisional+recombination lines, outward 
    324          * 7    collisional+recombination lines, reflected 
     320         * 4    diffuse emission, lines + continuum, outward 
     321         * 5    diffuse emission, lines + continuum, reflected 
     322         * 
     323         * 6    diffuse continuous emission outward direction 
     324         * 7    diffuse continuous emission, reflected 
    325325         * 
    326326         * 8    total transmitted, lines and continuum 
     
    333333        int nOption , 
    334334 
    335         /* the number of cells + 1*/ 
    336         long int nEnergy , 
     335        /* the number of cells */ 
     336        long int nEnergy, 
     337 
     338        /* the index of the lowest and highest energy bounds to use. */ 
     339        long ipLoEnergy, 
     340        long ipHiEnergy, 
    337341 
    338342        /* the returned spectrum, same size is two energy spectra (see option), returns nEnergy -1 pts */ 
     
    340344 
    341345{ 
    342         /* this pointer will bet set to one of the cloudy continuum arrays */ 
    343         realnum *cont ,  
    344                 refac; 
    345         long int ncell , j; 
    346  
    347         /* flag saying whether we will need to free cont at the end */ 
    348         bool lgFREE; 
     346        realnum refac; 
    349347 
    350348        DEBUG_ENTRY( "cdSPEC2()" ); 
    351349 
     350        ASSERT( ipLoEnergy >= 0 ); 
     351        ASSERT( ipLoEnergy < ipHiEnergy ); 
     352        ASSERT( ipHiEnergy < rfield.nupper ); 
     353        ASSERT( nEnergy == (ipHiEnergy-ipLoEnergy+1) ); 
     354        ASSERT( nEnergy >= 2 ); 
     355 
    352356        ASSERT( nOption <= NUM_OUTPUT_TYPES ); 
    353357 
    354         if( nOption == 1 ) 
    355         { 
    356                 /* this is the incident continuum, col 2 of punch continuum command */ 
    357                 cont = rfield.flux_total_incident; 
    358                 lgFREE = false; 
    359         } 
    360         else if( nOption == 2 ) 
    361         { 
    362                 /* the attenuated transmitted continuum, no diffuse emission, 
    363                  * col 3 of punch continuum command */ 
    364                 cont = rfield.flux; 
    365                 lgFREE = false; 
    366         } 
    367         else if( nOption == 3 ) 
    368         { 
    369                 /* reflected incident continuum, col 6 of punch continuum command */ 
    370                 lgFREE = false; 
    371                 cont = rfield.ConRefIncid; 
    372         } 
    373         else if( nOption == 4 ) 
    374         { 
    375                 /* diffuse continuous emission outward direction  */ 
    376                 cont = (realnum*)MALLOC( sizeof(realnum)*(size_t)rfield.nupper ); 
    377                 /* need to free the vector once done */ 
    378                 lgFREE = true; 
    379                 refac = (realnum)radius.r1r0sq*geometry.covgeo; 
    380                 for( j=0; j<rfield.nflux; ++j) 
    381                 { 
    382                         cont[j] = rfield.ConEmitOut[j]*refac; 
    383                 } 
    384         } 
    385         else if( nOption == 5 ) 
    386         { 
    387                 /* reflected diffuse continuous emission */ 
    388                 cont = (realnum*)MALLOC( sizeof(realnum)*(size_t)rfield.nupper ); 
    389                 /* need to free the vector once done */ 
    390                 lgFREE = true; 
    391                 for( j=0; j<rfield.nflux; ++j) 
    392                 { 
    393                         cont[j] = rfield.ConEmitReflec[j]; 
    394                 } 
    395         } 
    396         else if( nOption == 6 ) 
    397         { 
    398                 /* all outward lines,   */ 
    399                 cont = (realnum*)MALLOC( sizeof(realnum)*(size_t)rfield.nupper ); 
    400                 /* need to free the vector once done */ 
    401                 lgFREE = true; 
    402                 /* correct back to inner radius */ 
    403                 refac = (realnum)radius.r1r0sq*geometry.covgeo; 
    404                 for( j=0; j<rfield.nflux; ++j) 
    405                 { 
    406                         cont[j] = rfield.outlin[j]*refac; 
    407                 } 
    408         } 
    409         else if( nOption == 7 ) 
    410         { 
    411                 /* all reflected lines */ 
    412                 if( geometry.lgSphere ) 
    413                 { 
    414                         refac = 0.; 
    415                 } 
    416                 else 
    417                 { 
    418                         refac = 1.; 
    419                 } 
    420  
    421                 cont = (realnum*)MALLOC( sizeof(realnum)*(size_t)rfield.nupper ); 
    422                 /* need to free the vector once done */ 
    423                 lgFREE = true; 
    424                 for( j=0; j<rfield.nflux; ++j) 
    425                 { 
    426                         /* units of lines here are to cancel out with tricks applied to continuum cells 
    427                          * when finally extracted below */ 
    428                         cont[j] = rfield.reflin[j]*refac; 
    429                 } 
    430         } 
    431         else if( nOption == 8 ) 
    432         { 
    433                 /* total transmitted continuum */ 
    434                 cont = (realnum*)MALLOC( sizeof(realnum)*(size_t)rfield.nupper ); 
    435                 /* need to free the vector once done */ 
    436                 lgFREE = true; 
    437                 /* correct back to inner radius */ 
    438                 refac = (realnum)radius.r1r0sq*geometry.covgeo; 
    439                 for( j=0; j<rfield.nflux; ++j) 
    440                 { 
    441                         /* units of lines here are to cancel out with tricks applied to continuum cells 
    442                          * when finally extracted below */ 
    443                         cont[j] = (rfield.ConEmitOut[j]+ rfield.outlin[j])*refac 
    444                                           + rfield.flux[j]*(realnum)radius.r1r0sq; 
    445                 } 
    446         } 
    447         else if( nOption == 9 ) 
    448         { 
    449                 /* total reflected continuum */ 
    450                 cont = (realnum*)MALLOC( sizeof(realnum)*(size_t)rfield.nupper ); 
    451                 /* need to free the vector once done */ 
    452                 lgFREE = true; 
    453                 for( j=0; j<rfield.nflux; ++j) 
    454                 { 
    455                         /* units of lines here are to cancel out with tricks applied to continuum cells 
    456                          * when finally extracted below */ 
    457                         cont[j] = ((rfield.ConRefIncid[j]+rfield.ConEmitReflec[j]) + 
     358        for( long i = 0; i < nEnergy; i++ ) 
     359        { 
     360                long j = ipLoEnergy + i; 
     361 
     362                if( j >= rfield.nflux ) 
     363                { 
     364                        ReturnedSpectrum[i] = SMALLFLOAT; 
     365                        continue; 
     366                } 
     367 
     368                if( nOption == 1 ) 
     369                { 
     370                        /* this is the incident continuum, col 2 of punch continuum command */ 
     371                        ReturnedSpectrum[i] = rfield.flux_total_incident[j]; 
     372                } 
     373                else if( nOption == 2 ) 
     374                { 
     375                        /* the attenuated transmitted continuum, no diffuse emission, 
     376                         * col 3 of punch continuum command */ 
     377                        ReturnedSpectrum[i] = rfield.flux[j]; 
     378                } 
     379                else if( nOption == 3 ) 
     380                { 
     381                        /* reflected incident continuum, col 6 of punch continuum command */ 
     382                        ReturnedSpectrum[i] = rfield.ConRefIncid[j]; 
     383                } 
     384                else if( nOption == 4 ) 
     385                { 
     386                        /* correct back to inner radius */ 
     387                        refac = (realnum)radius.r1r0sq*geometry.covgeo; 
     388                        ReturnedSpectrum[i] = (rfield.outlin[j]+rfield.ConEmitOut[j])*refac; 
     389                } 
     390                else if( nOption == 5 ) 
     391                { 
     392                        /* all reflected diffuse emission */ 
     393                        if( geometry.lgSphere ) 
     394                        { 
     395                                refac = 0.; 
     396                        } 
     397                        else 
     398                        { 
     399                                refac = 1.; 
     400                        } 
     401 
     402                        ReturnedSpectrum[i] = (rfield.reflin[j]+rfield.ConEmitReflec[j])*refac; 
     403                } 
     404                else if( nOption == 6 ) 
     405                { 
     406                        /* correct back to inner radius */ 
     407                        refac = (realnum)radius.r1r0sq*geometry.covgeo; 
     408                        ReturnedSpectrum[i] = rfield.outlin[j]*refac; 
     409                } 
     410                else if( nOption == 7 ) 
     411                { 
     412                        /* all reflected line emission */ 
     413                        if( geometry.lgSphere ) 
     414                        { 
     415                                refac = 0.; 
     416                        } 
     417                        else 
     418                        { 
     419                                refac = 1.; 
     420                        } 
     421 
     422                        ReturnedSpectrum[i] = rfield.reflin[j]*refac; 
     423                } 
     424                else if( nOption == 8 ) 
     425                { 
     426                        /* total transmitted continuum */ 
     427                        /* correct back to inner radius */ 
     428                        refac = (realnum)radius.r1r0sq*geometry.covgeo; 
     429                        ReturnedSpectrum[i] = (rfield.ConEmitOut[j]+ rfield.outlin[j])*refac 
     430                                + rfield.flux[j]*(realnum)radius.r1r0sq; 
     431                } 
     432                else if( nOption == 9 ) 
     433                { 
     434                        /* total reflected continuum */ 
     435                        ReturnedSpectrum[i] = ((rfield.ConRefIncid[j]+rfield.ConEmitReflec[j]) + 
    458436                                rfield.reflin[j]); 
    459437                } 
    460         } 
    461         else if( nOption == 10 ) 
    462         { 
    463                 /* this is exp(-tau) */ 
    464                 cont = (realnum*)MALLOC( sizeof(realnum)*(size_t)rfield.nupper ); 
    465                 /* need to free the vector once done */ 
    466                 lgFREE = true; 
    467                 for( j=0; j<nEnergy; ++j) 
    468                 { 
     438                else if( nOption == 10 ) 
     439                { 
     440                        /* this is exp(-tau) */ 
    469441                        /* This is the TOTAL attenuation in both the continuum and lines.   
    470442                         * Jon Miller discovered that the line attenuation was missing in 07.02 */ 
    471                         cont[j] = opac.ExpmTau[j]*rfield.trans_coef_total[j]; 
    472                 } 
    473         } 
    474         else 
    475         { 
    476                 fprintf(ioQQQ," cdSPEC called with impossible nOption (%i)\n", nOption); 
    477                 cdEXIT(EXIT_FAILURE); 
    478         } 
    479  
    480         /* now generate the continua */ 
    481         for( ncell = 0; ncell < nEnergy; ++ncell ) 
    482         { 
    483         if( ncell >= rfield.nflux ) 
    484                 { 
    485                         ReturnedSpectrum[ncell] = SMALLFLOAT; 
     443                        ReturnedSpectrum[i] = opac.ExpmTau[j]*rfield.trans_coef_total[j]; 
    486444                } 
    487445                else 
    488446                { 
    489                         ReturnedSpectrum[ncell] = cont[ncell]; 
    490                 } 
    491                 ASSERT( ReturnedSpectrum[ncell] >=0.f ); 
    492         } 
    493  
    494         /* need to free the vector once done if this flag was set */ 
    495         if( lgFREE ) 
    496         { 
    497                 free(cont); 
    498         } 
     447                        fprintf(ioQQQ," cdSPEC called with impossible nOption (%i)\n", nOption); 
     448                        cdEXIT(EXIT_FAILURE); 
     449                } 
     450 
     451                ASSERT( ReturnedSpectrum[i] >=0.f ); 
     452        } 
     453 
    499454        return; 
    500455}