/*************************************************************************** * Copyright (C) 2005 by Carsten Niehaus * * cniehaus@kde.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "spectrum.h" #include "element.h" #include #include double Spectrum::minBand() { double value = ( *m_bandlist.begin() ).wavelength; QValueList::const_iterator it = m_bandlist.begin(); const QValueList::const_iterator itEnd = m_bandlist.end(); for (;it!=itEnd;++it) { if ( value > ( *it ).wavelength ) value = ( *it ).wavelength; } return value; } double Spectrum::maxBand() { double value = ( *m_bandlist.begin() ).wavelength; QValueList::const_iterator it = m_bandlist.begin(); const QValueList::const_iterator itEnd = m_bandlist.end(); for (;it!=itEnd;++it) { if ( value < ( *it ).wavelength ) value = ( *it ).wavelength; } return value; } Spectrum* Spectrum::adjustToWavelength( double min, double max ) { Spectrum *spec = new Spectrum(); QValueList::const_iterator it = m_bandlist.begin(); const QValueList::const_iterator itEnd = m_bandlist.end(); for ( ; it != itEnd; ++it ) { if ( ( *it ).wavelength < min || ( *it ).wavelength > max ) continue; spec->addBand( *it ); } spec->adjustMinMax(); return spec; } void Spectrum::adjustIntensities() { int maxInt = 0; QValueList::Iterator it = m_bandlist.begin(); const QValueList::Iterator itEnd = m_bandlist.end(); //find the highest intensity for ( ; it != itEnd; ++it ) { if ( ( *it ).intensity > maxInt ) maxInt = ( *it ).intensity; } //check if an adjustment is needed or not if ( maxInt == 1000 ) return; double max = ( double ) maxInt; //now adjust the intensities. it = m_bandlist.begin(); for ( ; it != itEnd; ++it ) { double curInt = ( ( double )( *it ).intensity ); double newInt = max*1000/curInt; ( *it ).intensity = qRound( newInt ); } } QValueList Spectrum::wavelengths( double min, double max ) { QValueList list; QValueList::const_iterator it = m_bandlist.begin(); const QValueList::const_iterator itEnd = m_bandlist.end(); for ( ; it != itEnd; ++it ) { if ( ( *it ).wavelength < min || ( *it ).wavelength > max ) continue; list.append( ( *it ).wavelength ); } return list; } QString Spectrum::bandsAsHtml() { QString html = "Chemical datai"; html += ""; QValueList::const_iterator it = m_bandlist.begin(); const QValueList::const_iterator itEnd = m_bandlist.end(); for (;it!=itEnd;++it) { html += QString( "" ) + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "\n"; } html += "
" + i18n( "Wavelength: %1 nm" ).arg( ( *it ).wavelength ) + "" + i18n( "Intensity: %1" ).arg( ( *it ).intensity ) + "" + i18n( "Probability: %1 108s-1" ).arg( ( *it ).aki ) + "" + i18n( "Energy 1: %1" ).arg( ( *it ).energy1 ) + "" + i18n( "Energy 2: %1" ).arg( ( *it ).energy2 ) + "" + i18n( "Electron Configuration 1: %1" ).arg( ( *it ).electronconfig1 ) + "" + i18n( "Electron Configuration 2: %1" ).arg( ( *it ).electronconfig2 ) + "" + i18n( "Term 1: %1" ).arg( ( *it ).term1 ) + "" + i18n( "Term 2: %1" ).arg( ( *it ).term2 ) + "" + i18n( "J 1: %1" ).arg( ( *it ).J1 ) + "" + i18n( "J 2: %1" ).arg( ( *it ).J2 ) + "
"; html += ""; return html; }