// boshcp.h -- A C++/Qt version of the Bremser C13 prediction table.
// See Bremser W, "Expectation Ranges of 13C NMR ChemicalShifts", Mag. Res.
// Chem. 23(4):271-275
// Derived from Java implementation by Christoph Steinbeck, see copyright
// notice below

/* BremserOneSphereHOSECodePredictor.java
 *
 * Copyright (C) 1997 - 2000  Dr. Christoph Steinbeck
 *
 * Contact: steinbeck@ice.mpg.de
 *
 * This software is published and distributed under artistic license.
 * The intent of this license is to state the conditions under which this Package 
 * may be copied, such that the Copyright Holder maintains some semblance
 * of artistic control over the development of the package, while giving the 
 * users of the package the right to use and distribute the Package in a
 * more-or-less customary fashion, plus the right to make reasonable modifications.
 *
 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, 
 * INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND 
 * FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * The complete text of the license can be found in a file called LICENSE 
 * accompanying this package.
 */

#include <qfile.h>
#include <qtextstream.h>
#include <qstringlist.h>
#include <qstring.h>
#include <qlist.h>

#include <kstddirs.h>
#include <kdebug.h>
#include <klocale.h>

#include "boshcp.h"

HOSECodeShiftRange::HOSECodeShiftRange(QString c, double s, double conf, QString m, 
		     double ma, double mi, int f, int l)
    {
      code = c;
      shift = s;
      confidenceLimit = conf;
      multiplicity = m;
      maxShift = ma;
      minShift = mi;
      fourSphereCount = f;
      lineCount = l;
      valid = true;
    }
		
QString HOSECodeShiftRange::toString()
    {
      QString tmp;
      QString s("delta_C: ");
      tmp.setNum(shift);
      s.append(tmp);
      s.append("(");
      s.append(multiplicity);
      s.append(")");
      //s.append(" for code ");
      //s.append(code); 
      //s.append(" with confidence limit ");
      s.append(" +/- ");
      tmp.setNum(confidenceLimit);
      s.append(tmp);
      s.append(i18n( " in shift range " ));
      tmp.setNum(maxShift);
      s.append(tmp);
      s.append("-"); 
      tmp.setNum(minShift); 
      s.append(tmp);
      return s; 
    }

  void BremserOneSphereHOSECodePredictor::prepareHashTable()
    {
		QString boshcpdata, s;
		QStringList hosecodeline; 
		QString key, mult;
		double shift, conf, min, max;
		int foursphere, lines;
		
		
		boshcpdata = locate( "data", "kdrawchem/boshcp.txt" );
		if ( !KStandardDirs::exists( boshcpdata ) )
			kdError()<<"Fatal: boshcp.txt not found!"<<endl;

		QFile boshcpfile( boshcpdata );
		boshcpfile.open( IO_ReadOnly );
		QTextStream t( &boshcpfile );
		while ( !t.eof() )
		{
			s = t.readLine();
			hosecodeline = QStringList::split( " ", s );
			key = hosecodeline[ 0 ];
			shift = hosecodeline[ 1 ].toDouble();
			conf = hosecodeline[ 2 ].toDouble();
			mult = hosecodeline[ 3 ];
			max = hosecodeline[ 4 ].toDouble();
			min = hosecodeline[ 5 ].toDouble();
			foursphere = hosecodeline[ 6 ].toInt();
			lines = hosecodeline[ 7 ].toInt();
			ht.put( key, HOSECodeShiftRange( key, shift, conf, mult, max, min, foursphere, lines ) );
		}

		boshcpfile.close();
	}
