src/Level2/TrnsTable1D.cc
// #include <iostream>
// using namespace std;
// modified by LK, Dec. 2007
// imported into TTable1D with slight modifications on interface
// by DCT 10/07/09
include 
using namespace std;
modified by LK, Dec. 2007
imported into TTable1D with slight modifications on interface
by DCT 10/07/09
include using namespace std ; modified by LK Dec . 2007 imported into TTable1D with slight modifications on interface by DCT 10 / 07 / 09
void TTable1D::dbwrite( const string& fileName, 
                        const std::string& compname, 
                        const double& specfreq,
                        const int& numberspins,
                        const int& loop,
                        const vector<string> & header) const
{
    ofstream ostr;					        
    ostr.open(fileName.c_str(), ios::out);	
    ostr << "; " << "\n";
    vector<string>::const_iterator vs;
    for(vs = header.begin(); vs != header.end(); vs++)
    {
        ostr << "; " << (*vs).c_str() << "\n";
    }
    ostr << "; " << "\n";
    std::vector<double>    freqs;
    std::vector<int>       mx_index; 
    std::vector<double>    freqout;
    std::vector<double>    ampout;
    std::vector<double>    phaseout;
    double           freq;
    double           normal = 1.0;
    double           amptemp, ampsum, phasetemp;
    unsigned long    bincount = 0;
    const double     freqtol = 0.1/specfreq;    
    const double     phasetol = 50.0;           
    unsigned long    k;                         
    int              foundone = 0;
    int ns=numberspins;
    mx_index = this->Sort(0,-1,0);     
    for(long ii=0; ii<this->size(); ii++)
    {
        freqs.push_back(-this->Fr(mx_index[ii])/(2.0*PI*specfreq));
    }
    normal=pow(2.0,(ns-1));
    normal=normal/2;
    std::cout << "Normalization in dbwrite: " << normal << " \n";
    {
        std::vector<double>::iterator itf;
        long i;
        for(i=0, itf=freqs.begin(); i<this->size(); i++, itf++)
        {
		    freq = *itf;
		    {
		        amptemp   =  norm(this->I(mx_index[i]))/normal;
		        phasetemp = -RAD2DEG*phase(this->I(mx_index[i]));
		        if (bincount == 0) 
		        {
		            freqout.push_back(freq);
		            ampout.push_back(amptemp);
		            phaseout.push_back(phasetemp);
		            ++bincount;
		        }
		        else
		        { 
		            for(k=0; k < bincount && foundone == 0; k++) 
		            {
		                if(freq >= freqout[k]-freqtol && freq <= freqout[k]+freqtol)
		                {
		                    if (phasetemp >= phaseout[k]-phasetol && phasetemp <= phaseout[k]+phasetol)
		                    {
		                        ampsum      =  ampout[k]+amptemp;
		                        freqout[k]  = (ampout[k]*freqout[k]  + amptemp*freq)/ampsum;
		                        phaseout[k] = (ampout[k]*phaseout[k] + amptemp*phasetemp)/ampsum;
		                        ampout[k]  +=  amptemp;
		                        foundone = 1;                           
		                    }
		                }
		            }
		            if (foundone == 0)
		            {
		                freqout.push_back(freq);
		                ampout.push_back(amptemp);
		                phaseout.push_back(phasetemp);
		                ++bincount;
		            }
		            foundone = 0;
		        }
		  }
		}
	}
	{
		std::vector<double>::iterator Fr, Am, Ph;
		unsigned long i;
		char tempFr[100];
		char tempAm[100];
		char tempPh[100];
		for(i=0, Fr=freqout.begin(), Am=ampout.begin(), Ph=phaseout.begin(); i<bincount; i++, Fr++, Am++, Ph++)
		{
		    ostr << compname;                    
		    ostr << "\t" <<  loop;                
		    ostr << "\t" <<  0;                    
		    ostr << "\t" <<  i;                    
#ifdef _MSC_VER
			sprintf_s(tempFr, "%.8f", *Fr);
			sprintf_s(tempAm, "%.8f", *Am);
		    sprintf_s(tempPh, "%.8f", ((*Ph) * (-1.0)) );
#else
			sprintf(tempFr, "%.8f", *Fr);
			sprintf(tempAm, "%.8f", *Am);
			sprintf(tempPh, "%.8f", ((*Ph) * (-1.0)) );
#endif
		    ostr << "\t" << tempFr;     
			ostr << "\t" << tempAm;     
		    ostr << "\t" << tempPh ;    
		    ostr << "\n";       
		}
	}
    ostr.close();     
}
void TTable1D :: dbwrite ( const string & fileName , const std :: string & compname , const double & specfreq , const int & numberspins , const int & loop , const vector < string > & header ) const { ofstream ostr ; ostr . open ( fileName . c_str ( ) , ios :: out ) ; ostr << " " << " \n " ; vector < string > :: const_iterator vs ; for ( vs = header . begin ( ) ; vs != header . end ( ) ; vs ++ ) { ostr << " " << ( * vs ) . c_str ( ) << " \n " ; } ostr << " " << " \n " ; std :: vector < double > freqs ; std :: vector < int > mx_index ; std :: vector < double > freqout ; std :: vector < double > ampout ; std :: vector < double > phaseout ; double freq ; double normal = 1.0 ; double amptemp , ampsum , phasetemp ; unsigned long bincount = 0 ; const double freqtol = 0.1 / specfreq ; const double phasetol = 50.0 ; unsigned long k ; int foundone = 0 ; int ns = numberspins ; mx_index = this -> Sort ( 0 , -1 , 0 ) ; for ( long ii = 0 ; ii < this -> size ( ) ; ii ++ ) { freqs . push_back ( - this -> Fr ( mx_index [ ii ] ) / ( 2.0 * PI * specfreq ) ) ; } normal = pow ( 2.0 , ( ns - 1 ) ) ; normal = normal / 2 ; std :: cout << " " << normal << " \n " ; { std :: vector < double > :: iterator itf ; long i ; for ( i = 0 , itf = freqs . begin ( ) ; i < this -> size ( ) ; i ++ , itf ++ ) { freq = * itf ; { amptemp = norm ( this -> I ( mx_index [ i ] ) ) / normal ; phasetemp = - RAD2DEG * phase ( this -> I ( mx_index [ i ] ) ) ; if ( bincount == 0 ) { freqout . push_back ( freq ) ; ampout . push_back ( amptemp ) ; phaseout . push_back ( phasetemp ) ; ++ bincount ; } else { for ( k = 0 ; k < bincount && foundone == 0 ; k ++ ) { if ( freq >= freqout [ k ] - freqtol && freq <= freqout [ k ] + freqtol ) { if ( phasetemp >= phaseout [ k ] - phasetol && phasetemp <= phaseout [ k ] + phasetol ) { ampsum = ampout [ k ] + amptemp ; freqout [ k ] = ( ampout [ k ] * freqout [ k ] + amptemp * freq ) / ampsum ; phaseout [ k ] = ( ampout [ k ] * phaseout [ k ] + amptemp * phasetemp ) / ampsum ; ampout [ k ] += amptemp ; foundone = 1 ; } } } if ( foundone == 0 ) { freqout . push_back ( freq ) ; ampout . push_back ( amptemp ) ; phaseout . push_back ( phasetemp ) ; ++ bincount ; } foundone = 0 ; } } } } { std :: vector < double > :: iterator Fr , Am , Ph ; unsigned long i ; char tempFr [ 100 ] ; char tempAm [ 100 ] ; char tempPh [ 100 ] ; for ( i = 0 , Fr = freqout . begin ( ) , Am = ampout . begin ( ) , Ph = phaseout . begin ( ) ; i < bincount ; i ++ , Fr ++ , Am ++ , Ph ++ ) { ostr << compname ; ostr << " \t " << loop ; ostr << " \t " << 0 ; ostr << " \t " << i ; #ifdef _MSC_VER sprintf_s ( tempFr , " " , * Fr ) ; sprintf_s ( tempAm , " " , * Am ) ; sprintf_s ( tempPh , " " , ( ( * Ph ) * ( -1.0 ) ) ) ; #else sprintf ( tempFr , " " , * Fr ) ; sprintf ( tempAm , " " , * Am ) ; sprintf ( tempPh , " " , ( ( * Ph ) * ( -1.0 ) ) ) ; #endif ostr << " \t " << tempFr ; ostr << " \t " << tempAm ; ostr << " \t " << tempPh ; ostr << " \n " ; } } ostr . close ( ) ; }
include <iostream>
using namespace std;
modified by LK, Dec. 2007
imported into TTable1D with slight modifications on interface
by DCT 10/07/09
include <iostream > using namespace std ; modified by LK Dec . 2007 imported into TTable1D with slight modifications on interface by DCT 10 / 07 / 09
// Input // Note       : Frequencies and Rates are in 1/sec // Added to LK's version so that only the filename needs  // to be passed in (no iostream type). This will work better // in the python implementation.  DCT (10/06/09). // Construct a file // Open file // write out header lines // Use something like half the minimum // coupling const. divided by field // strength for freqtol /* Get index array in PPM order -------------------------------------*/ /* Convert frequencies to PPM ---------------------------------------*/ // there is no more reference spins, normalization is taken // place by the formula below, where ns is the number of spins //std::cout << "normal is " << normal<< std::endl; //std::cout << "numberofspins is " << ns<< std::endl; // DCT - added on 11/18/09 /* Simple peak blending based on Freqtol and Phasetol ---------------*/ //LK no need for low and high     //if ((freq > lowppm && freq < reflow) || (freq > refhigh && freq < highppm)) // std::cout << "phase is " << phase(this->I(mx_index[i]))<< std::endl; //this is to write out the very first set of numbers //this is equivalent to while loop in matlab //end of else    /* Output values to text file --------------------------------------------*/ // metabolite name // loop number // group number in metabolite // line index in metabolite // frequency in ppm // intensity // phase //ostr << "bincount = " << bincount << "\n"; // Close file