//J-Group Scattering/Extinction calculator, based on C. F. Bohren and D. R. Huffman,
// Absorption and Scattering of Light by Small Particles http://onlinelibrary.wiley.com/book/10.1002/9783527618156
//Original version of the PCJ_BHMie function translated from fortran by Charles Brock, NOAA ESRL, and provided "as is" (few comments)
//for interpretation of what the code is doing see the B&H book and also e.g. http://rime.aos.wisc.edu/MW/models/bhmie.shtml
//Wrapper code written by Ed Dunlea, Mike Cubison and Pedro Campuzano Jost (PCJ)
//Contact Pedro.CampuzanoJost-1@colorado.edu and jose.jimenez@colorado.edu for feedback or bug reports
//Version 2.0, Last updated on 10/30/2016
// University of Colorado at Boulder, Jimenez Research Group
#pragma rtglobals=3
static constant NANG=20 //NANG: Number of angles between 0 and 180 deg to integrate the scattering calculations over. We use a default of 20 steps
//***********************************************************************************************************************************************************
Function/WAVE PCJ_dNdlogDp2Scat(dNdlogD, Dmid, MyOpt, dlogD, minbin, maxbin, Wvl, RInd, ImRInd, OType)
//function to calculate extinction over a TIME SERIES of size distributions, originally written by Mike Cubison
//Small tweaks by PCJ
//dNdlogDp: Number Size Distribution (2DWave, with rows=time and columns=SizeBins), equally spaced in dlog space
//Dmid: Midpoint Diamter in nm
//MyOpt: Name of the time dependent wave that will contain the calculated optical values.
// The wave reference to the new wave is returned by this function
//DlogD: Delta logDp (size resolution), for DMA data typically 1/32 of 1/64, depending on channel resolution
//minbin, maxbin: Use to limit the size bins used in the calculation, e.g. if you want to exclude supermicron particles.
// Set to NaN to use the full size distribution
//Wvl: Wavelength of interest in nm
//RInd: Real part of the refractive index (scattering)
//ImRInd: Imaginary part of the refractive index (absorption) Note that unlike RInd, ImRind is typically strongly wavelenght depedent in the VIS
//OType: Output Type. 0 to calculate scattering, 1 for extinction and 2 for Backscattering.
Wave dNdlogD, Dmid
string MyOpt
Variable dlogD, minbin, maxbin, Wvl, RInd, ImRind, OType
Variable TCol=dimsize(dNdlogD,0) //number of size distributions
make/o/N=(TCol) $MyOpt
Wave Dest = $MyOpt //Output wave with Name MyOpt
Dest=NaN
make/FREE/N=(numpnts(Dmid)) dp_log, dNdlogDp_Temp //dNdlogDp_Temp Single size distribution, dp_logDp is delta logDp with the same dimmension as dNdlogDp_Temp
dp_log=dlogD
Variable n
for (n=0; n